-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
59 lines (48 loc) · 1.55 KB
/
index.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
#!/usr/bin/env node
import * as chalk from 'chalk';
import * as cmd from 'commander';
import * as process from 'process';
import { init, add, dev, build, publish } from './cmd';
import { log } from './lib';
import { getVersion } from './util';
import { exeCmd } from './util/common';
cmd.version(getVersion());
cmd.command('init [type] [name]')
.description('Init an app, which should be [website | spa].')
.option('-t, --typescript', 'Use typescript or not.')
.action((type: string, name: string, options: any) => {
init(type, name, options);
});
cmd.command('add [path] [name]')
.description('Add a page.')
.action((path: string, name: string) => {
add(path, name);
});
cmd.command('build')
.description('Build an app before deploying.')
.option('-w, --watch', 'Build and watch.')
.option('-p, --pre-deploy', 'Build and bind pre-deploy environment.')
.action((options: { watch: boolean, preDeploy: boolean }) => {
build(false, !!options.watch, !!options.preDeploy);
});
cmd.command('dev')
.description('Build and watch in development mode.')
.action(() => {
dev();
});
cmd.command('publish')
.description('Publish statics to CDN server, including js, css and images.')
.option('-c, --clear', 'Clear the bucket before publish.')
.action((options: any) => {
publish(options && options.clear);
});
cmd.command('*')
.action((...args) => {
args.pop();
log.error(` Error: command not found: ${ args.join(' ') }`);
cmd.outputHelp();
});
cmd.parse(process.argv);
if (!cmd.args.length) {
cmd.outputHelp();
}