forked from ssvlabs/ssv-web
-
Notifications
You must be signed in to change notification settings - Fork 1
/
plopfile.cjs
89 lines (85 loc) · 2.26 KB
/
plopfile.cjs
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const Templates = {
FC: 'Component',
Modal: 'Modal',
ForwardRef: 'ComponentWithForwardRef'
};
const getPrompts = (template) => {
return [
{
// Raw text input
type: 'input',
// Variable name for this input
name: 'name',
// Prompt to display on command line
message: "What's your components name?"
},
{
// Raw text input
type: 'input',
// Variable name for this input
name: 'path',
// Prompt to display on command line
message: 'Which folder?',
default: 'src/app/atomicComponents/'
// choices: uiComponents,
},
{
// Raw text input
type: 'input',
// Variable name for this input
name: 'componentType',
// Prompt to display on command line
message: 'Which HTML Tag would you like to use?',
default: 'div'
// choices: uiComponents,
},
{
type: 'confirm',
name: 'addProps',
message: 'Do you want to add custom component props?',
description: '(type CmpProps = { someProp: string })',
default: true
},
{
// Raw text input
type: 'confirm',
// Variable name for this input
name: 'wantFolder',
// Prompt to display on command line
message: 'Should it be in a folder of its own?',
default: false
// choices: uiComponents,
}
];
};
const getActions = (template) => (data) => {
const name = '/{{pascalCase name}}';
const path = `{{path}}${name.repeat(data.wantFolder + 1)}.tsx`;
return [
{
// Add a new file
type: 'add',
// Path for the new file
path: path,
// Handlebars template used to generate content of new file
templateFile: `plop-templates/${template}.hbs`
}
];
};
module.exports = (plop) => {
plop.setGenerator('cmp', {
description: 'Create a component',
prompts: getPrompts(Templates.FC),
actions: getActions(Templates.FC)
});
plop.setGenerator('modal', {
description: 'Create a Modal component',
prompts: getPrompts(Templates.Modal),
actions: getActions(Templates.Modal)
});
plop.setGenerator('cmp-forward-ref', {
description: 'Create a component forwardRef',
prompts: getPrompts(Templates.ForwardRef),
actions: getActions(Templates.ForwardRef)
});
};