forked from alan2207/bulletproof-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (54 loc) · 1.48 KB
/
index.js
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
const path = require('path');
const fs = require('fs');
const featuresDir = path.join(process.cwd(), 'src/features');
const features = fs.readdirSync(featuresDir);
/**
*
* @type {import('plop').PlopGenerator}
*/
module.exports = {
description: 'Component Generator',
prompts: [
{
type: 'input',
name: 'name',
message: 'component name',
},
{
type: 'list',
name: 'feature',
message: 'Which feature does this component belong to?',
choices: ['ROOT', ...features],
when: () => features.length > 0,
},
{
type: 'input',
name: 'folder',
message: 'folder in components',
when: ({ feature }) => !feature || feature === 'ROOT',
},
],
actions: (answers) => {
const componentGeneratePath =
!answers.feature || answers.feature === 'ROOT'
? 'src/components/{{folder}}'
: 'src/features/{{feature}}/components';
return [
{
type: 'add',
path: componentGeneratePath + '/{{properCase name}}/index.ts',
templateFile: 'generators/component/index.ts.hbs',
},
{
type: 'add',
path: componentGeneratePath + '/{{properCase name}}/{{properCase name}}.tsx',
templateFile: 'generators/component/Component.tsx.hbs',
},
{
type: 'add',
path: componentGeneratePath + '/{{properCase name}}/{{properCase name}}.stories.tsx',
templateFile: 'generators/component/Component.stories.tsx.hbs',
},
];
},
};