You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.2 KiB
59 lines
1.2 KiB
#!/usr/bin/env node
|
|
|
|
const { Command } = require('commander');
|
|
const Prompt = require('inquirer');
|
|
const Create = require('./command/create');
|
|
const program = new Command();
|
|
|
|
|
|
|
|
const handleExit = () => {
|
|
process.exit();
|
|
};
|
|
|
|
const handleError = (e) => {
|
|
console.error('ERROR! 执行过程中出现错误');
|
|
console.error(e);
|
|
console.log('退出执行...');
|
|
process.exit(1);
|
|
};
|
|
|
|
process.on('SIGINT', handleExit);
|
|
process.on('uncaughtException', handleError);
|
|
|
|
const Cli = program.command('tis-cli');
|
|
|
|
Cli.version(require('../package.json').version).usage('<command> [options]');
|
|
|
|
// 选项
|
|
const templateOpts = [
|
|
{
|
|
type: 'list',
|
|
name: 'templateType',
|
|
message: '模板类型',
|
|
choices: [
|
|
{
|
|
value: 1, name: 'platform 框架模板'
|
|
},
|
|
{
|
|
value: 2, name: 'application 应用模板'
|
|
},
|
|
{
|
|
value: 3, name: 'component 组件库模板'
|
|
}
|
|
]
|
|
}
|
|
];
|
|
|
|
// 通过模板创建项目
|
|
Cli
|
|
.command('create <projectName>')
|
|
.description('通过选择模板类型,创建新的项目')
|
|
.action(async (projectName) => {
|
|
Prompt.prompt(templateOpts).then(result => {
|
|
// 创建
|
|
Create(projectName, result.templateType);
|
|
})
|
|
});
|
|
|
|
Cli.parse(process.argv)
|