-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·42 lines (38 loc) · 1.32 KB
/
index.js
File metadata and controls
executable file
·42 lines (38 loc) · 1.32 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
#! /usr/bin/env node
const program = require('commander');
const chalk = require('chalk');
const logSymbols = require('log-symbols');
const tplList = require('./lib/tplList');
const tplInit = require('./lib/tplInit');
const version = require('./package.json').version;
/*** mj -V | --version ***/
program
.version(version)
/*** mj init <template> <project> ***/
program
.command('init <template> <project>')
.description('初始化项目模版')
.action((template, project) => {
// 根据模版名下载对应模版,并以project为本地项目名
const { downloadUrl } = tplList[template];
tplInit.downloadFun(downloadUrl, project).then(() => {
tplInit.inquirerFun(project)
.then(() => {
console.log(logSymbols.success, chalk.yellow('项目初始化成功'));
})
.catch(err => {
console.log(logSymbols.error, chalk.red('项目初始化失败'));
})
}).catch(err => {})
});
/*** mj list ***/
program
.command('list')
.description('查看所有模版')
.action(() => {
// 打印所有模版
for (let i in tplList) {
console.log(logSymbols.info, chalk.blue(`${i} ${tplList[i].description}`));
}
});
program.parse(process.argv);