1 | #!/usr/bin/env node
|
2 | import arg from "arg";
|
3 | const parseArgs = (argv) => arg({
|
4 | "--version": Boolean,
|
5 | "--help": Boolean,
|
6 |
|
7 | "-v": "--version",
|
8 | "-h": "--help",
|
9 | }, {
|
10 | permissive: true,
|
11 | argv,
|
12 | });
|
13 | const commands = {
|
14 | dev: () => import("../cli/microsite-dev").then(({ default: cmd }) => cmd),
|
15 | build: () => import("../cli/microsite-build").then(({ default: cmd }) => cmd),
|
16 | serve: () => import("../cli/microsite-serve").then(({ default: cmd }) => cmd),
|
17 | };
|
18 | async function run() {
|
19 | let [command = "dev", ...argv] = process.argv.slice(2);
|
20 | if (command.startsWith("-")) {
|
21 | argv = [command, ...argv];
|
22 | command = 'dev';
|
23 | }
|
24 | if (argv[0] === "--")
|
25 | argv = argv.slice(1);
|
26 | const args = parseArgs(argv);
|
27 | if (args["--help"]) {
|
28 | console.log(`
|
29 | Usage
|
30 | $ microsite <command>
|
31 |
|
32 | Available commands
|
33 | ${Object.keys(commands).join(", ")}
|
34 | Options
|
35 | --version, -v Version number
|
36 | --help, -h Displays this message
|
37 | For more information run a command with the --help flag
|
38 | $ microsite build --help
|
39 | `);
|
40 | }
|
41 | else if (args["--version"]) {
|
42 | console.log(`Microsite v${process.env.npm_package_version}`);
|
43 | }
|
44 | else {
|
45 | switch (command) {
|
46 | case "dev":
|
47 | return import("../cli/microsite-dev.js").then(({ default: cmd }) => cmd(argv));
|
48 | case "serve":
|
49 | return import("../cli/microsite-serve.js").then(({ default: cmd }) => cmd(argv));
|
50 | case "build":
|
51 | return import("../cli/microsite-build.js").then(({ default: cmd }) => cmd(argv));
|
52 | }
|
53 | }
|
54 | }
|
55 | run();
|