-
-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathcli.js
58 lines (52 loc) · 2 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
#!/usr/bin/env node
import sade from 'sade';
import build from './build.js';
import start from './start.js';
import serve from './serve.js';
import * as kl from 'kolorist';
const prog = sade('wmr');
function bool(v) {
return v !== false && !/false|0/.test(v);
}
prog
.option('--public', 'Your web app root directory (default: ./public)')
.option('--out', 'Where to store generated files (default: ./dist)')
.option('--cwd', 'The working directory - equivalent to "(cd FOO && wmr)"')
.command('build', 'make a production build')
.option('--prerender', 'Pre-render the application to HTML')
.action(opts => {
opts.minify = opts.minify !== false && !/false|0/.test(opts.minify);
run(build(opts));
})
.command('serve', 'Start a production server')
.option('--out', 'Directory to serve (default: ./dist)')
.option('--port, -p', 'HTTP port to listen on (default: $PORT or 8080)')
.option('--host', 'HTTP host to listen on (default: localhost)')
.option('--http2', 'Use HTTP/2 (default: false)')
.option('--compress', 'Enable compression (default: enabled)')
.action(opts => {
opts.compress = bool(opts.compress);
run(serve(opts));
})
.command('start', 'Start a development server', { default: true })
.option('--port, -p', 'HTTP port to listen on (default: $PORT or 8080)')
.option('--host', 'HTTP host to listen on (default: localhost)')
.option('--http2', 'Use HTTP/2 (default: false)')
.option('--compress', 'Enable compression (default: enabled)')
.option('--sourcemap', 'Enable Source Maps')
.option('--profile', 'Generate build statistics')
.option('--reload', 'Switch off hmr and reload on file saves')
.action(opts => {
opts.optimize = !/false|0/.test(opts.compress);
opts.compress = bool(opts.compress);
if (/true/.test(process.env.PROFILE)) opts.profile = true;
run(start(opts));
});
prog.parse(process.argv);
function run(p) {
p.catch(err => {
const text = (process.env.DEBUG ? err.stack : err.message) || err + '';
process.stderr.write(`${kl.red(text)}\n`);
process.exit(p.code || 1);
});
}