-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (67 loc) · 2.92 KB
/
index.js
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
#!/usr/bin/env node
const fs = require('fs');
const program = require('commander');
const download = require('download-git-repo');
const handlebars = require('handlebars');
const inquirer = require('inquirer');
const ora = require('ora');
const chalk = require('chalk');
const symbols = require('log-symbols');
program.version('1.1.0', '-v, --version')
.command('init <name>')
.action((name,version) => {
// console.log(name,version)
if(!fs.existsSync(name)){inquirer.prompt([
{
name: 'description',
message: '请输入项目描述'
},
{
name: 'author',
message: '请输入作者名称'
},
{
name: 'version',
message: '请输入版本号'
}
]).then((answers) => {
const spinner = ora('正在下载模板...');
spinner.start();
download('direct:https://github.com/maxtcarry/mxt-vuecli3.git', name, {clone: true}, (err) => {
if(err){
spinner.fail();
console.log(symbols.error, chalk.red(err));
}else{
spinner.succeed();
const fileName = `${name}/package.json`;
//console.log(fileName)
fs.readFile(fileName, function (err, data) {
if (err) {
return console.error(err);
}
const newData =JSON.parse(data.toString());
newData.name = name;
newData.author= answers.author;
newData.description=answers.description;
newData.version = answers.version;
fs.writeFile(fileName ,JSON.stringify(newData,null,2), function(err) {
if (err) {
return console.error(err);
}
});
});
console.log(symbols.success, chalk.green('项目初始化完成'));
console.log(symbols.warning, chalk.green('注意 修改< vue.config.js >来满足自己的项目需求'));
console.log('|| cd '+ name +'');
console.log('|| npm install 安装集成的控件等');
console.log('|| npm run serve 启动本地环境');
console.log('|| npm run build 构建生产环境');
}
})
})
}else{
// 错误提示项目已存在,避免覆盖原有项目
console.log(symbols.error, chalk.red('项目已存在'));
}
})
program.parse(process.argv);