-
Notifications
You must be signed in to change notification settings - Fork 0
/
webapp.ts
76 lines (62 loc) · 1.43 KB
/
webapp.ts
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
#!/usr/bin/env node
/**
* @author 田尘殇Sean(sean.snow@live.com) create at 2018/10/2
*/
import { Command } from 'commander';
import * as path from 'path';
import templates from './template';
const pkg = require('./package.json');
const program = new Command();
program
.version(pkg.version, '-v, --version')
.description('A React Application Manager')
;
program
.command('create <name>')
.description(`创建一个Web app.
模板列表:
${templates.map(({ name, describe }) => `${name} - ${describe}`).join('\n ')}
样例:
arapp create -t react foo
`)
.option('-t, --template', '模板名称', 'react')
.action((command, options) => {
console.log(command, options.template);
})
;
program
.command('serve')
.description('启动一个开发服务器')
.option('-p, --port', '监听端口')
.action(() => {
run('serve', {});
})
;
program
.command('bundle')
.description('编译打包应用')
.action(() => {
process.env.NODE_ENV = 'production';
run('dll', {}).then(() => {
run('bundle', {});
});
})
;
program
.command('dll')
.description('创建依赖库')
.action(() => run('dll', {}))
;
program
.parse(process.argv)
;
function run(cmd, options) {
const cmdExecFile = path.join(__dirname, 'cmd', `${cmd}.js`);
try {
const handler = require(cmdExecFile);
return handler.execute(options);
} catch (e) {
console.error(e);
process.exit(1);
}
}