forked from chakra-ui/chakra-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plopfile.js
59 lines (51 loc) · 1.38 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
const capitalize = (str) => {
return str.charAt(0).toUpperCase() + str.slice(1)
}
const camelCase = (str) => {
return str.replace(/[-_](\w)/g, (_, c) => c.toUpperCase())
}
const workspaces = ["components", "hooks", "utilities"]
/**
* @param {import("plop").NodePlopAPI} plop
*/
module.exports = function main(plop) {
plop.setHelper("capitalize", (text) => {
return capitalize(camelCase(text))
})
plop.setGenerator("component", {
description: "Generates a component package",
prompts: [
{
type: "input",
name: "componentName",
message: "Enter component name:",
},
{
type: "input",
name: "description",
message: "The description of this component:",
},
{
type: "list",
name: "outDir",
message: "where should this component or package live?",
default: "packages",
choices: workspaces,
},
],
actions(answers) {
const actions = []
if (!answers) return actions
const { componentName, description, outDir } = answers
actions.push({
type: "addMany",
templateFiles: "plop/component/**",
destination: `./packages/{{outDir}}/{{dashCase componentName}}`,
base: "plop/component",
data: { description, componentName, outDir },
abortOnFail: true,
})
return actions
},
})
}