From c29341c30e9d2d0e638aa96888d8f11093531115 Mon Sep 17 00:00:00 2001 From: streakingman Date: Fri, 4 Mar 2022 15:30:09 +0800 Subject: [PATCH] =?UTF-8?q?feat(react-comp):=20=E6=94=AF=E6=8C=81=E5=AD=90?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E6=90=BA=E5=B8=A6=E6=96=87=E4=BB=B6=E5=90=8D?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- actions/react-comp.js | 23 ++++++++++++++--------- index.js | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) 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);