-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathplopfile.mjs
86 lines (77 loc) · 2.82 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
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
// See https://plopjs.com/
/** @typedef {import('plop').NodePlopAPI} NodePlopAPI */
/** @typedef {import('plop').ActionConfig} ActionConfig */
/**
* @param {string} name
* @returns string
*/
function templateFile(name) {
return `.plop/templates/${name}.hbs`
}
/** @param {NodePlopAPI} plop */
function componentGenerator(plop) {
plop.setGenerator('component', {
description: 'React component with tests, styles, and storybook docs',
prompts: [
{
type: 'input',
name: 'name',
message:
'Component name (e.g. "dropdown select", "sortable-table", "PromotionBanner")',
},
{
type: 'list',
name: 'storyType',
message:
'Story type (select "both" if unsure, and you can decide later which one to keep)',
choices: ['.mdx', '.tsx', 'both'],
default: 'both',
},
],
/** @param {{ name: string; storyType: '.mdx' | '.tsx' | 'both' }} */
actions({ storyType }) {
/** @type {Array<ActionConfig>} */
const actions = [
{
type: 'add',
path: 'src/{{dashCase name}}/index.ts',
templateFile: templateFile('component/index.ts'),
},
{
type: 'add',
path: 'src/{{dashCase name}}/{{dashCase name}}.tsx',
templateFile: templateFile('component/component.tsx'),
},
{
type: 'add',
path: 'src/{{dashCase name}}/{{dashCase name}}.module.css',
templateFile: templateFile('component/component.module.css'),
},
{
type: 'add',
path: 'src/{{dashCase name}}/{{dashCase name}}.test.tsx',
templateFile: templateFile('component/component.test.tsx'),
},
]
if (storyType === '.mdx' || storyType === 'both') {
actions.push({
type: 'add',
path: 'src/{{dashCase name}}/{{dashCase name}}.stories.mdx',
templateFile: templateFile('component/component.stories.mdx'),
})
}
if (storyType === '.tsx' || storyType === 'both') {
actions.push({
type: 'add',
path: 'src/{{dashCase name}}/{{dashCase name}}.stories.tsx',
templateFile: templateFile('component/component.stories.tsx'),
})
}
return actions
},
})
}
/** @param {NodePlopAPI} plop */
export default function (plop) {
componentGenerator(plop)
}