Files
webpage/app.js
T
2018-05-16 18:52:08 +08:00

143 lines
3.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
*
* @authors Tony.Deng (dengtongyu123@163.com)
* @date 2018-05-14 16:44:06
* @version $Id$
*/
const program = require('commander');
const inquirer = require('inquirer');
const util = require('./task/util');
const task = require('./task/task');
program
.version('0.1.0')
.command('new')
.alias('n')
.description('新建一个项目')
.option('-n, --name [pathName]', '构建路径名称')
.option('-t, --tpl [tplType]', '模版类型(pc or phone)')
.action(option => {
let config = Object.assign({
tpl: 0,
name: null
}, option)
//console.log(config)
let promps = [];
if(!config.name) {
promps.push({
type: 'input',
name: 'name',
message: '请输入需要创建的路径名:',
default: util.randomActName()
})
}
if(!config.tpl) {
promps.push({
type: 'list',
name: 'tpl',
message: '请选择需要创建的模板:',
choices: [
{
name: '1. tpl-pc',
value: 1
},
{
name: '2. tpl-phone',
value: 2
}
]
})
}
inquirer.prompt(promps).then(function (answers) {
//console.log('\n',answers)
option = Object.assign(answers,option);
//console.log(option);
//util.initPath(answers.name);
task.selectTpl(option.name,option.tpl);
})
})
program
.command('dev')
.alias('d')
.description('开发一个已存在的项目')
.option('-n, --name [pathName]', '开发路径名称')
.action(option => {
let config = Object.assign({
name: null
}, option)
//console.log(config)
let promps = [];
if(!config.name) {
promps.push({
type: 'input',
name: 'name',
message: '请输入需要开发的路径名:',
validate: function (input){
if(!input) {
return '不能为空'
}
return true
}
})
}
inquirer.prompt(promps).then(function (answers) {
//console.log('\n',answers)
option = Object.assign(answers,option);
//console.log(option.name);
//util.initPath(answers.name);
task.dev(option.name);
})
});
program
.command('pack')
.alias('b')
.description('打包构建一个已存在的项目')
.option('-n, --name [pathName]', '打包构建路径名称')
.action(option => {
let config = Object.assign({
name: null
}, option)
//console.log(config)
let promps = [];
if(!config.name) {
promps.push({
type: 'input',
name: 'name',
message: '请输入需要打包构建的路径名:',
validate: function (input){
if(!input) {
return '不能为空'
}
return true
}
})
}
inquirer.prompt(promps).then(function (answers) {
//console.log('\n',answers)
option = Object.assign(answers,option);
//console.log(option.name);
task.pack(option.name);
})
});
program.parse(process.argv)
//console.log(program);