-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.mjs
54 lines (46 loc) · 1.35 KB
/
plopfile.mjs
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
/* eslint-disable import/no-anonymous-default-export */
export default function (plop) {
const getComponentName = {
type: 'input',
name: 'name',
message: 'Please enter a component name.',
validate: (value) => {
if (/.+/.test(value)) {
return true;
}
return 'Component name is required!';
},
};
const getStorybookFileStatus = {
type: 'confirm',
name: 'storybook',
message: 'Do you want to add storybook?',
default: false,
};
const createComponentFile = {
type: 'add',
path: 'src/components/{{pascalCase name}}/index.tsx',
templateFile: 'templates/component.tsx.hbs',
};
const createStyleFile = {
type: 'add',
path: 'src/components/{{pascalCase name}}/style.css.ts',
templateFile: 'templates/style.css.ts.hbs',
};
const createStoryFile = {
type: 'add',
path: 'src/components/{{pascalCase name}}/{{pascalCase name}}.stories.tsx',
templateFile: 'templates/stories.tsx.hbs',
};
plop.setGenerator('Create component template files', {
description: 'Create templates',
prompts: [getComponentName, getStorybookFileStatus],
actions: (data) => {
const fileCreateActions = [createComponentFile, createStyleFile];
if (data && data.storybook) {
fileCreateActions.push(createStoryFile);
}
return fileCreateActions;
},
});
}