-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcli.js
executable file
·89 lines (81 loc) · 2.33 KB
/
cli.js
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env node
/* @flow */
// Need that because of regenerator runtime
require("babel-polyfill");
// $FlowFixMe
process.noDeprecation = true; // Suppress webpack deprecation warnings
const meow = require("meow");
const chalk = require("chalk");
const aik = require("./lib");
const cli = meow({
help: [
chalk.green("Usage"),
" $ aik filename.js",
"",
chalk.green("Options"),
` ${chalk.yellow("-b, --build")} Build production version for given entry point. [Default output: dist]`,
` ${chalk.yellow("-u, --base")} Base path with which URLs in build begins`,
` ${chalk.yellow("-p, --port")} Web server port. ${chalk.dim("[Default: 4444]")}`,
` ${chalk.yellow("-h, --host")} Web server host. ${chalk.dim("[Default: localhost]")}`,
` ${chalk.yellow("-n, --ngrok")} Exposes server to the real world by ngrok.`,
` ${chalk.yellow("-o, --open")} Opens web server URL in the default browser.`,
` ${chalk.yellow("-v, --version")} Shows version.`,
` ${chalk.yellow("--help")} Shows help.`,
"",
chalk.green("Examples"),
" $ aik filename.js --port 3000 -n",
chalk.dim(" Runs aik web server on 3000 port with ngrok."),
"",
" $ aik filename.js --build",
chalk.dim(" Builds filename.js for production use and saves the output to dist folder.")
].join("\n"),
flags: {
build: {
alias: "b"
},
base: {
type: "string",
alias: "u"
},
port: {
type: "string",
alias: "p"
},
host: {
type: "string",
alias: "h"
},
ngrok: {
type: "boolean",
alias: "n"
},
open: {
type: "boolean",
alias: "o"
},
version: {
type: "boolean",
alias: "v"
}
}
});
const input = cli.input || [];
const flags = cli.flags || {};
const errorHandler = err => {
if (err.formattedMessage) {
aik.print(err.formattedMessage, /* clear */ true);
} else {
// eslint-disable-next-line
console.log(chalk.red(err.stack || err));
}
process.exit(1);
};
aik.deprecation.flagDeprecationWarnings(flags, () => {
if (!input.length) {
console.log(cli.help); // eslint-disable-line
} else if (flags.build) {
aik.build(input, flags).catch(errorHandler);
} else {
aik.devServer(input, flags).catch(errorHandler);
}
});