-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
plopfile.js
117 lines (109 loc) · 3.16 KB
/
plopfile.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
module.exports = function (plop) {
const COMPONENT_TYPES = ['base', 'module'];
plop.setGenerator('component', {
prompts: async (inquirer) => {
const { type } = await inquirer.prompt({
type: 'list',
choices: COMPONENT_TYPES,
name: 'type',
message: 'Select Component type...',
});
const { name } = await inquirer.prompt({
type: 'input',
name: 'name',
message: `Enter ${type} component name...`,
});
return Promise.resolve({
type,
name,
});
},
actions: (data) => {
console.log(data);
const TEMPLATE_PATH = './templates/component';
const COMPONENT_PATH = './src/components/{{type}}/{{name}}';
const STORYBOOK_PATH = './storybook/stories/{{type}}';
const actions = [
{
type: 'add',
path: `${COMPONENT_PATH}/index.tsx`,
templateFile: `${TEMPLATE_PATH}/index.tsx.hbs`,
},
{
type: 'add',
path: `${COMPONENT_PATH}/props.ts`,
templateFile: `${TEMPLATE_PATH}/props.ts.hbs`,
},
{
type: 'add',
path: `${COMPONENT_PATH}/style.ts`,
templateFile: `${TEMPLATE_PATH}/style.ts.hbs`,
},
{
type: 'add',
path: `${COMPONENT_PATH}/view.tsx`,
templateFile: `${TEMPLATE_PATH}/view.tsx.hbs`,
},
{
type: 'add',
path: `${STORYBOOK_PATH}/{{pascalCase name}}.js`,
templateFile: `${TEMPLATE_PATH}/story.js.hbs`,
},
{
type: 'append',
path: `${STORYBOOK_PATH}/index.js`,
pattern: '/* PLOP_INJECT_IMPORT */',
template: "require('./{{pascalCase name}}');",
},
];
return actions;
},
});
plop.setGenerator('svg', {
prompts: async (inquirer) => {
const { name } = await inquirer.prompt({
type: 'input',
name: 'name',
message: 'Enter SVG name...',
});
return Promise.resolve({
name,
});
},
actions: (data) => {
console.log(data);
const TEMPLATE_PATH = './templates/svg';
const COMPONENT_PATH = './src/components/base/SVG';
const STORYBOOK_PATH = './storybook/stories/base';
const actions = [
{
type: 'add',
path: `${COMPONENT_PATH}/{{pascalCase name}}.tsx`,
templateFile: `${TEMPLATE_PATH}/component.tsx.hbs`,
},
{
type: 'append',
path: `${COMPONENT_PATH}/index.tsx`,
pattern: '/* PLOP_INJECT_IMPORT */',
template:
"export { default as {{pascalCase name}} } from './{{pascalCase name}}';",
},
{
type: 'append',
path: `${STORYBOOK_PATH}/SVG.js`,
pattern: '/* PLOP_INJECT_IMPORT */',
template: ' {{pascalCase name}},',
},
{
type: 'append',
path: `${STORYBOOK_PATH}/SVG.js`,
pattern: '{/* PLOP_INJECT_INSTANCE*/}',
template: ` <SVGWrapper label="{{pascalCase name}}">
<{{pascalCase name}} fill="#000" />
</SVGWrapper>`,
},
];
return actions;
},
});
};