@hhy5277/ns-cli
Version:
```shell # install it globally $ npm install -g ns-cli --registry http://199.10.9.178:8081/repository/npm-group/
56 lines (48 loc) • 1.53 kB
JavaScript
const program = require('commander');
const figlet = require('figlet');
const chalk = require('chalk');
program
.command('create <app-name>')
.alias('c')
.description('create a new project')
.option('-f, --force', 'overwrite target directory if it exist') // 是否强制创建,当文件夹已经存在
.action((name, options) => {
// 在 create.js 中执行创建任务
require('../lib/create.js')(name, options)
})
// 配置 config 命令
program
.command('config [value]')
.description('inspect and modify the config')
.option('-g, --get <path>', 'get value from option')
.option('-s, --set <path> <value>')
.option('-d, --delete <path>', 'delete option from config')
.action((value, options) => {
console.log(value, options)
})
// 配置 ui 命令
program
.command('ui')
.description('start and open ns-cli ui')
.option('-p, --port <port>', 'Port used for the UI Server')
.action((option) => {
console.log(option)
})
program
// 配置版本号信息
.version(`v${require('../package.json').version}`)
.usage('<command> [option]')
program
.on('--help', () => {
console.log('\r\n' + figlet.textSync('nanshui', {
font: 'Ghost',
horizontalLayout: 'default',
verticalLayout: 'default',
width: 80,
whitespaceBreak: true
}));
console.log(`\r\nRun ${chalk.cyan(`ns <command> --help`)} for detailed usage of given command\r\n`)
})
// 解析用户执行命令传入参数
program.parse(process.argv);