1 | #!/usr/bin/env node
|
2 | 'use strict'
|
3 | const program = require('commander')
|
4 | const pkg = require('../package')
|
5 | const chalk = require('chalk')
|
6 |
|
7 | program
|
8 | .version(pkg.version)
|
9 |
|
10 | /**
|
11 | * 用例
|
12 | */
|
13 |
|
14 | program
|
15 | .usage('init <template-name> [project-name]')
|
16 |
|
17 | program.on('--help', function () {
|
18 | console.log(' Examples:')
|
19 | console.log()
|
20 | console.log(chalk.gray(' # create a new project with an official template'))
|
21 | console.log(` $ ${pkg.name} init template-name project-name`)
|
22 | console.log()
|
23 | })
|
24 |
|
25 |
|
26 | /**
|
27 | * 添加模板
|
28 | */
|
29 |
|
30 | program
|
31 | .command('add')
|
32 | .description('Add a new template')
|
33 | .alias('a')
|
34 | .action(() => {
|
35 | require('../lib/add')()
|
36 | })
|
37 |
|
38 | /**
|
39 | * 移除模板
|
40 | */
|
41 |
|
42 | program
|
43 | .command('remove')
|
44 | .description('Remove a template')
|
45 | .alias('r')
|
46 | .action(() => {
|
47 | require('../lib/remove')()
|
48 | })
|
49 |
|
50 | /**
|
51 | * 重置模板
|
52 | */
|
53 |
|
54 | program
|
55 | .command('reset')
|
56 | .description('Reset template')
|
57 | .action(() => {
|
58 | require('../lib/reset')()
|
59 | })
|
60 |
|
61 | /**
|
62 | * 更新模板
|
63 | */
|
64 |
|
65 | program
|
66 | .command('update')
|
67 | .description('Update a template')
|
68 | .alias('u')
|
69 | .action(() => {
|
70 | require('../lib/update')()
|
71 | })
|
72 |
|
73 |
|
74 | /**
|
75 | * 列出所有模板
|
76 | */
|
77 |
|
78 | program
|
79 | .command('list')
|
80 | .description('List all the templates')
|
81 | .alias('l')
|
82 | .action(() => {
|
83 | require('../lib/list')()
|
84 | })
|
85 |
|
86 |
|
87 | /**
|
88 | * 生成项目
|
89 | */
|
90 |
|
91 | program
|
92 | .command('init')
|
93 | .description('Create a new project')
|
94 | .alias('i')
|
95 | .action(() => {
|
96 | require('../lib/init')()
|
97 | })
|
98 |
|
99 |
|
100 | /**
|
101 | * 输出帮助信息
|
102 | */
|
103 |
|
104 | function help () {
|
105 | program.parse(process.argv)
|
106 | if (program.args.length < 1) return program.help()
|
107 | }
|
108 | help()
|