diff --git a/actions/react-comp.js b/actions/react-comp.js index 352edb6..1c81ae1 100644 --- a/actions/react-comp.js +++ b/actions/react-comp.js @@ -1,16 +1,21 @@ const { execSync } = require('child_process'); const inquirer = require('inquirer'); const { fileGenerator } = require('../utils/file-generator'); +const { checkVersion } = require('../utils/check-version'); -const reactComp = async () => { - let { compName } = await inquirer.prompt([ - { - type: 'input', - name: 'compName', - message: '请输入组件名', - default: 'MyComp', - }, - ]); +const reactComp = async (compName) => { + checkVersion(); + if (!compName) { + let { compName: inputCompName } = await inquirer.prompt([ + { + type: 'input', + name: 'compName', + message: '请输入组件名', + default: 'MyComp', + }, + ]); + compName = inputCompName; + } const nameArray = compName.split(''); nameArray[0] = nameArray[0].toLowerCase(); diff --git a/index.js b/index.js index 22f1922..53636ed 100644 --- a/index.js +++ b/index.js @@ -30,7 +30,7 @@ program .description('安装lint和工程化依赖以及简单配置') .action(setProject); program - .command('react-comp') + .command('react-comp [compName]') .description('快速生成react组件相关文件') .action(reactComp);