vesh-cli
Version:
码农村nodejs版本VESH框架脚手架搭建器
74 lines (66 loc) • 4.12 kB
JavaScript
const co = require('co');
const prompt = require('co-prompt');
const chalk = require('chalk');
const fs = require('fs');
const V = require('gcl/com/coooders/io/tool');
const tool = require('gcl/com/coooders/common/tool');
const child_process = require('child_process');
module.exports = () => {
co(function*() {
try {
// 分步接收用户输入的参数
const tplName = yield prompt('项目名:');
const description = yield prompt('描述:');
console.log(chalk.green('文件复制中……'));
const ret = yield V.copyDir(process.env.NODE_PATH, './');
console.log(chalk.green('复制完成'));
let nginxfile = yield tool.callback(fs.readFile, fs, './nginx.conf');
//console.log(nginxfile.toString());
nginxfile = nginxfile.toString().replace(/\/Users\/baibing\/work\/cv_zc\/Entry/g, V.formatPath('./').replace(/\\+/g, '/').replace(/\S+:/g, ''));
yield tool.callback(fs.writeFile, fs, './nginx.conf', nginxfile, { encoding: 'utf-8' });
//console.log(nginxfile);
let processfile = yield tool.callback(fs.readFile, fs, './processes.json');
//console.log(nginxfile.toString());
processfile = processfile.toString().replace(/\/Users\/baibing\/work\/cv_zc\/Entry/g, V.formatPath('./').replace(/\\+/g, '/').replace(/\S+:/g, ''));
yield tool.callback(fs.writeFile, fs, './processes.json', processfile, { encoding: 'utf-8' });
const pjson = tool.json(yield tool.callback(fs.readFile, fs, './package.json'));
pjson.name = tplName;
pjson.version = '0.1.0';
pjson.description = description;
fs.writeFile('./package.json', tool.toJsonString(pjson).replace(/\/Users\/baibing\/work\/cv_zc\/Entry/g, V.formatPath('./').replace(/\\+/g, '/').replace(/\S+:/g, '')).replace(/\}/g, '}\r\n'), { encoding: 'utf-8' }, (err) => {
//fs.unlink('./package.json', e => {});
if (err) {
console.log(chalk.red(err.message));
process.exit();
} else {
console.log(chalk.green('VESH项目创建完毕,开始初始化!!\n'));
console.log(chalk.green('\tnpm run init\t可以启动初始化'));
console.log(chalk.green('\tnpm run coding\t自动编译'));
console.log(chalk.green('\tnpm run debug\t自动编译并启动测试环境的PM2和nginx'));
console.log(chalk.green('\tnpm run start\t启动正式环境'));
console.log(chalk.green('\tnpm run stop\t停止全部PM2和nginx'));
console.log(chalk.green('\tnpm run restart\t重启PM2和nginx'));
process.exit();
/*const cpro = child_process.fork('/usr/local/bin/npm', ['i']);
cpro.on('close', function(code) {
console.log(chalk.green('VESH项目创建完成,加油 Man!!\n'));
const cpro2 = child_process.fork('/usr/local/bin/npm', ['run', 'init']);
cpro2.on('close', function(code) {
console.log(chalk.green('VESH项目初始化完成,可执行如下命令'));
console.log(chalk.green('\tnpm run coding\t自动编译\n'));
console.log(chalk.green('\tnpm run debug\t自动编译并启动测试环境的PM2和nginx\n'));
console.log(chalk.green('\tnpm run start\t启动正式环境\n'));
console.log(chalk.green('\tnpm run stop\t停止全部PM2和nginx\n'));
console.log(chalk.green('\tnpm run restart\t重启PM2和nginx\n'));
process.exit();
});
});*/
}
})
} catch (e) {
console.log(chalk.red(e.message));
process.exit();
}
})
};