forked from lgwebdream/fe-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreact2code.js
More file actions
57 lines (49 loc) · 1.35 KB
/
react2code.js
File metadata and controls
57 lines (49 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// eslint-disable-next-line no-unused-vars
const { join } = require('path');
const { prompt } = require('inquirer');
const { generateReactCode } = require('../lib/utils/react2Code');
// 交互问题采集
const questions = [
{
type: 'list',
name: 'style',
message: 'style of writing: ',
choices: ['hooks', 'class'],
default: 'hooks',
},
{
type: 'list',
name: 'state',
message: 'state of writing: ',
choices: ['useReducer', 'redux', 'mobx', 'recoil'],
default: 'useReducer',
},
{
type: 'list',
name: 'ui',
message: 'ui of writing: ',
choices: ['antd', 'material-ui'],
default: 'antd',
},
];
const templatePath = join(__dirname, '../lib/react/');
const react2code = program => {
program
.command('react2code')
.alias('r2c')
.usage('-o <output>')
.description('🍉 generate react code of crud')
.requiredOption('-o, --output <output>', 'path of generation file')
.action(({ output }) => {
console.log(`output@`, output);
prompt(questions).then(answers => {
const { style, state, ui } = answers;
console.log(`answer@`, style, state, ui);
// write path
const toPath = join(process.cwd(), output);
// generate react crud code
generateReactCode(templatePath, toPath, answers);
});
});
};
module.exports = react2code;