Skip to content

Commit

Permalink
feat(react-comp): 支持子命令携带文件名参数
Browse files Browse the repository at this point in the history
  • Loading branch information
StreakingMan committed Mar 4, 2022
1 parent 3dc1fec commit c29341c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
23 changes: 14 additions & 9 deletions actions/react-comp.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ program
.description('安装lint和工程化依赖以及简单配置')
.action(setProject);
program
.command('react-comp')
.command('react-comp [compName]')
.description('快速生成react组件相关文件')
.action(reactComp);

Expand Down

0 comments on commit c29341c

Please sign in to comment.