Skip to content

Commit

Permalink
fix(react-comp): 文件夹创建命令
Browse files Browse the repository at this point in the history
  • Loading branch information
StreakingMan committed Mar 2, 2022
1 parent 95c3af8 commit 8f8a5ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
18 changes: 12 additions & 6 deletions actions/react-comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const inquirer = require('inquirer');
const { fileGenerator } = require('../utils/file-generator');

const reactComp = async () => {
const { compName } = await inquirer.prompt([
let { compName } = await inquirer.prompt([
{
type: 'input',
name: 'compName',
Expand All @@ -12,19 +12,25 @@ const reactComp = async () => {
},
]);

execSync(`touch ${compName}`);
execSync(`cd ${compName}`);
const nameArray = compName.split('');
nameArray[0] = nameArray[0].toLowerCase();
compName = nameArray.join();
nameArray[0] = nameArray[0].toUpperCase();
const CompName = nameArray.join();

execSync(`mkdir ${CompName}`);
execSync(`cd ${CompName}`);
fileGenerator({
templateName: 'reactCompIndex',
option: { compName },
option: { compName, CompName },
});
fileGenerator({
templateName: 'reactCompInterface',
option: { compName },
option: { compName, CompName },
});
fileGenerator({
templateName: 'reactCompStyle',
option: { compName },
option: { compName, CompName },
});
};

Expand Down
12 changes: 3 additions & 9 deletions utils/file-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const generatorTemplateFileMap = {
};

const fileGenerator = ({ templateName, option = {} }) => {
const { react, ts, compName } = option;
const { react, ts, compName, CompName } = option;
const cwd = process.cwd();
const file = path.join(
path.join(__dirname, '../templates'),
Expand All @@ -30,16 +30,10 @@ const fileGenerator = ({ templateName, option = {} }) => {
ts,
generatedAt: new Date().toLocaleString(),
version,
compName,
CompName,
};

if (compName) {
const nameArray = compName.split('');
nameArray[0] = nameArray[0].toLowerCase();
data.compName = nameArray.join();
nameArray[0] = nameArray[0].toUpperCase();
data.CompName = nameArray.join();
}

const filename = generatorTemplateFileMap[templateName];

fse.outputFileSync(path.join(cwd, filename), ejs.render(template, data));
Expand Down

0 comments on commit 8f8a5ba

Please sign in to comment.