forked from cultureamp/kaizen-design-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plopfile.js
73 lines (70 loc) · 2.08 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
module.exports = (
/** @type {import('plop').NodePlopAPI} */
plop
) => {
plop.setGenerator("basic component", {
description: "Generate a basic component",
prompts: [
{
type: "input",
name: "componentName",
message: "What is the component name?",
},
{
type: "confirm",
name: "isSubcomponent",
message: "Is this a subcomponent?",
default: false,
},
{
type: "input",
name: "parentComponentName",
message: "What is the parent component name?",
when: answers => answers.isSubcomponent,
},
{
type: "input",
name: "packageName",
message: "What is the package name?",
default: ({ componentName, isSubcomponent, parentComponentName }) =>
plop.getHelper("kebabCase")(
isSubcomponent ? parentComponentName : componentName
),
},
],
actions: ({ isSubcomponent }) => {
if (isSubcomponent) {
return [
{
type: "addMany",
destination:
"packages/{{kebabCase packageName}}/src/{{pascalCase parentComponentName}}/components",
base: "plop-templates/basic-component/src",
templateFiles: "plop-templates/basic-component/src/**/*.hbs",
},
]
}
return [
{
type: "addMany",
destination: "packages/{{kebabCase packageName}}",
base: "plop-templates/basic-component",
templateFiles: "plop-templates/basic-component/**/*.hbs",
skipIfExists: true,
},
{
type: "modify",
path: "packages/{{kebabCase packageName}}/index.ts",
transform: (content, answers) => {
const componentName = plop.getHelper("pascalCase")(
answers.componentName
)
const exportStatement = `export * from "./src/${componentName}"`
if (content.includes(exportStatement)) return content
return `${content.trim()}\n${exportStatement}\n`
},
},
]
},
})
}