import inquirer, { Questions } from 'inquirer' import path from 'path' import log from '../utils/log' import {createFormConfigFile} from '../routers/customFormRouter' import {createQueryConfig} from '../routers/queryFormRouter' type newOptions = { folder: string, configType: 'form' | 'queryForm', configName: string } type newQuestions = {[propName: string]: any;}[] | Questions const questions: newQuestions = [ { type: 'file-tree-selection', name: 'folder', message: '请选择文件夹路径', onlyShowDir: true }, { type: 'list', name: 'configType', message: '请选择配置类型', choices: ['form', 'queryForm'] }, { type: 'input', name: 'configName', message: '请输入form配置文件名称', default: 'config.lego.js', when: (answers: newOptions) => answers.configType === 'form' }, { type: 'input', name: 'configName', message: '请输入query form配置文件夹名称', default: 'config-lego', when: (answers: newOptions) => answers.configType === 'queryForm' } ] export default function() { inquirer.prompt(questions) .then((answers: newOptions) => { const configPath = path.resolve(answers.folder, answers.configName) if (answers.configType === 'form') { createFormConfigFile(configPath) log.success(`成功创建普通表单文件 ${configPath}`) } else { createQueryConfig(path.resolve(answers.folder, configPath)) log.success(`成功创建query表单 ${configPath}`) } }) }