-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathcmd.cjs
More file actions
executable file
·60 lines (51 loc) · 1.46 KB
/
Copy pathcmd.cjs
File metadata and controls
executable file
·60 lines (51 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env node
const pkg = require("./package.json");
// Node check
require("@11ty/node-version-check")(pkg, {
message: function (requiredVersion) {
return (
"eleventy-dev-server requires Node " +
requiredVersion +
". You will need to upgrade Node!"
);
},
});
const { Logger, Cli } = require("./cli.js");
try {
const argv = Cli.parseArgs(process.argv.slice(2));
// Older Node friendly import workaround (this is a CommonJS file)
import("obug").then(({ createDebug }) => {
const debug = createDebug("Eleventy:DevServer");
debug("CLI arguments: %o", argv);
});
process.on("unhandledRejection", (error, promise) => {
Logger.fatal("Unhandled rejection in promise:", promise, error);
});
process.on("uncaughtException", (error) => {
Logger.fatal("Uncaught exception:", error);
});
if (argv.version) {
console.log(Cli.getVersion());
} else if (argv.help) {
console.log(Cli.getHelp());
} else {
let cli = new Cli();
cli.serve({
input: argv.dir,
port: argv.port,
host: argv.host,
domDiff: argv.domdiff,
});
process.on("SIGINT", async () => {
await cli.close();
process.exitCode = 0;
});
}
} catch (e) {
if (e.code?.startsWith("ERR_PARSE_ARGS_")) {
let message = e.message.endsWith(".") ? e.message : `${e.message}.`;
Logger.fatal(`${message} Use --help to see the list of supported commands.`);
} else {
Logger.fatal("Fatal Error:", e)
}
}