-
-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathcli.js
More file actions
50 lines (45 loc) · 1.73 KB
/
Copy pathcli.js
File metadata and controls
50 lines (45 loc) · 1.73 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
#!/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');
prog
.option('--cwd', 'Your web app root directory (default: ./public)')
.option('--out', 'Where to store generated files (default: ./dist)')
.command('build', 'make a production build')
.action(opts => {
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 = /true|false/.test(opts.compress) ? opts.compress !== 'false' : opts.compress || true;
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')
.action(opts => {
opts.optimize = !/false|0/.test(opts.compress);
if (/true|false/.test(opts.compress)) opts.compress = opts.compress !== 'false';
if (/true/.test(process.env.PROFILE)) opts.profile = true;
run(start(opts));
});
prog.parse(process.argv);
function run(p) {
p.catch(err => {
const text = err.stack;
process.stderr.write(`${kl.red(text)}\n`);
process.exit(p.code || 1);
});
}