UNPKG

cwj-cli

Version:

76 lines (69 loc) 2 kB
const inquirer = require('inquirer') const { program } = require('commander') const { createAction, addComponentAction, addView } = require('./action') const { judgeNeedCreateDir } = require('../utils/index') const createCommand = () => { program .command('create <project> [others...]') .description('自动创建项目') .action(createAction) program .command('addCom') .description('自动生成组件') .action(async () => { const answer = await inquirer.prompt([ { type: 'input', name: 'name', message: '请输入组件名称:', validate: (input) => { if (input.length > 0) { return true } return '请确认输入组件名称' }, }, { type: 'input', name: 'dest', message: '请输入目标文件地址,默认为src/component:', default: 'src/component', }, ]) const dirExist = await judgeNeedCreateDir(answer.dest) if (dirExist) { addComponentAction(answer.name, answer.dest) } }) program .command('addView') .description('自动生成页面') .action(async () => { const answer = await inquirer.prompt([ { type: 'input', name: 'name', message: '请输入页面名称:', validate: (input) => { if (input.length > 0) { return true } return '请确认输入页面名称' }, }, { type: 'input', name: 'dest', message: '请输入目标文件地址,默认为src/views:', default: 'src/views', }, ]) const dirExist = await judgeNeedCreateDir(answer.dest) if (dirExist) { addView(answer.name, answer.dest) } }) } module.exports = { createCommand, }