-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.js
85 lines (79 loc) · 2.24 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
function appendToIndex(plop) {
return function (path, templatePath) {
return function (data) {
// inserts a line into index.js while maintaining alphabetical sort.
const fs = require("fs");
templateFile = fs.readFileSync(templatePath, "utf8");
pathFile = fs.readFileSync(path, "utf8");
const renderedTemplate = plop.renderString(templateFile, data);
let imports = pathFile.split("\n").filter(function (i) {
return i !== "";
});
imports = [...imports, renderedTemplate];
imports.sort();
imports.push("");
fs.writeFileSync(path, imports.join("\n"), "utf8");
return "append to index";
};
};
}
module.exports = function (plop) {
appendToIndex = appendToIndex(plop);
plop.setGenerator("hook", {
description: "hook",
prompts: [
{
type: "input",
name: "name",
message: "hook name please",
},
],
actions: [
{
type: "add",
path: "src/hooks/{{camelCase name}}.tsx",
templateFile: ".plop-templates/hook.hbs",
},
{
type: "add",
path: "src/hooks/{{camelCase name}}.stories.mdx",
templateFile: ".plop-templates/hook.stories.hbs",
},
{
type: "add",
path: "src/hooks/{{camelCase name}}.test.tsx",
templateFile: ".plop-templates/hook.test.hbs",
},
appendToIndex("src/hooks/index.ts", ".plop-templates/hook.index.hbs"),
appendToIndex("src/index.ts", ".plop-templates/hook.root.index.hbs"),
],
});
plop.setGenerator("component", {
description: "component",
prompts: [
{
type: "input",
name: "name",
message: "component name please",
},
],
actions: [
{
type: "add",
path: "src/{{properCase name}}.tsx",
templateFile: ".plop-templates/component.hbs",
},
{
type: "add",
path: "src/{{properCase name}}.stories.tsx",
templateFile: ".plop-templates/component.stories.hbs",
},
{
type: "add",
path: "src/{{properCase name}}.test.tsx",
templateFile: ".plop-templates/component.test.hbs",
},
appendToIndex("src/index.ts", ".plop-templates/component.index.hbs"),
],
});
};