-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
39 lines (33 loc) · 1.2 KB
/
Copy pathinit.js
File metadata and controls
39 lines (33 loc) · 1.2 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
'use strict';
const exec = require('child_process').exec;
const co = require('co');
const prompt = require('co-prompt');
const config = require('../templates');
const chalk = require('chalk');
module.exports = () => {
co(function * () {
// 处理用户输入
let tplName = yield prompt('模板名称: ');
let projectName = yield prompt('项目名称: ');
let gitUrl;
let branch;
if(!config.tpl[tplName]){
console.log(chalk.red('\n × Template does not exit!'));
process.exit();
}
gitUrl = config.tpl[tplName].url;
branch = config.tpl[tplName].branch;
// git命令,远程拉取项目并自定义项目名
let cmdStr = `git clone ${gitUrl} ${projectName} && cd ${projectName} && git checkout ${branch}`;
console.log(chalk.white('\n Start generating...'));
exec(cmdStr,(error,stdout,stderr) => {
if(error){
console.log(error);
process.exit();
}
console.log(chalk.green('\n √ Generation completed!'));
console.log(`\n cd ${projectName} && npm install \n`);
process.exit();
});
});
};