ssr-to-html
Version:
Crawl a server rendered application and output html files
69 lines (66 loc) • 2.68 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __reExport = (target, module2, copyDefault, desc) => {
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
for (let key of __getOwnPropNames(module2))
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
}
return target;
};
var __toESM = (module2, isNodeMode) => {
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
};
var import_arg = __toESM(require("arg"));
var import__ = __toESM(require("."));
const opts = (0, import_arg.default)({
"--out": String,
"--port": Number,
"--wait": Number,
"--path": [String],
"--404": String,
"--help": Boolean,
"-o": "--out",
"-p": "--path",
"-h": "--help"
}, { permissive: false, argv: process.argv.slice(2) });
if (opts["--help"]) {
console.log(`
Usage
$ ssr-to-html --out ./dist -- <cmd>
Options
--out, -o The directory that the ".html" files will be written to.
--port The port of the server to connect to. This also sets "process.env.PORT". Setting to 0 will disable this timeout. (default to a random available port)
--wait The total amount of time in ms to wait for the server to start on the specified port. (default 30000)
--path, -p An additional path to crawl. (default will crawl from /)
--404 The path to the 404 page. (default /404/)
--help, -h Shows this message.
Examples
$ ssr-to-html --out ./dist -- npm start
$ ssr-to-html -o ./dist --port 3001 -- node/index.js
$ ssr-to-html -o ./dist -p / -p /non-crawlable-path -- node ./index.js
`);
} else {
(async () => {
if (!opts["--out"]) {
throw new Error("The --out option is required and specifies where files should be output.");
}
await (0, import__.default)({
cmd: opts._.join(" "),
out: opts["--out"],
port: opts["--port"],
wait: opts["--wait"],
paths: opts["--path"],
notFoundPath: opts["--404"]
});
})().catch((err) => {
console.error(err);
process.exit(1);
});
}