-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplopfile.js
129 lines (125 loc) · 4.12 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
module.exports = function (plop) {
const toKebabCase = (str) => {
return str.toLowerCase().replace(/ /g, "-");
};
const toCamelCase = (str) => {
return str
.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, (match, index) =>
index === 0 ? match.toLowerCase() : match.toUpperCase(),
)
.replace(/\s+/g, "");
};
// create your generators here
plop.setGenerator("example", {
description: "new example in examples folder",
prompts: [
{
type: "input",
name: "name",
message: "Example name (Sentence case):",
},
],
actions: (data) => {
const exampleSlug = toKebabCase(data.name);
const exampleCamel = toCamelCase(data.name);
const destinationPath = `examples/${exampleSlug}`;
const templatePath = "example-templates/next";
const templateContentPath = "example-templates/web-content";
const contentDestinationPath = `apps/web/src/app/examples/${exampleSlug}`;
const demoUrlName = toCamelCase(data.name);
const demoUrl = `https://${exampleSlug}.examples.flows.sh`;
const exampleSourceUrlName = `${toCamelCase(data.name)}Source`;
const exampleSourceUrl = `https://github.com/RBND-studio/flows.sh/tree/main/examples/${exampleSlug}`;
return [
// Copy all files from the template directory
{
type: "addMany",
destination: destinationPath,
base: templatePath,
templateFiles: `${templatePath}/**/*`,
globOptions: { dot: true },
},
// Copy all files from the content directory
{
type: "addMany",
destination: contentDestinationPath,
base: templateContentPath,
templateFiles: `${templateContentPath}/**/*`,
globOptions: { dot: true },
},
// README.md
{
type: "modify",
path: `${destinationPath}/README.md`,
pattern: /(-- PLOP TITLE HERE --)/gi,
template: `${data.name}`,
},
{
type: "modify",
path: `${destinationPath}/README.md`,
pattern: /(-- PLOP EXAMPLE SLUG HERE --)/gi,
template: `${exampleSlug}`,
},
// layout.tsx
{
type: "modify",
path: `${destinationPath}//src/app/layout.tsx`,
pattern: /(-- PLOP TITLE HERE --)/gi,
template: `${data.name}`,
},
// providers.tsx
{
type: "modify",
path: `${destinationPath}/src/app/providers.tsx`,
pattern: /(-- PLOP EXAMPLE SLUG HERE --)/gi,
template: `${exampleSlug}`,
},
// package.json
{
type: "modify",
path: `${destinationPath}/package.json`,
pattern: /(-- PLOP EXAMPLE SLUG HERE --)/gi,
template: `${exampleSlug}`,
},
// shared/src/links.ts
{
type: "modify",
path: "packages/shared/src/links.ts",
pattern: /\/\/ --PLOP_NEW_EXAMPLE_LINK--/g,
template: `${demoUrlName}: "${demoUrl}",\n ${exampleSourceUrlName}: "${exampleSourceUrl}",\n // --PLOP_NEW_EXAMPLE_LINK--`,
},
// content.tsx
{
type: "modify",
path: `${contentDestinationPath}/content.tsx`,
pattern: /(-- PLOP TITLE HERE --)/gi,
template: `${data.name}`,
},
{
type: "modify",
path: `${contentDestinationPath}/content.tsx`,
pattern: /(-- PLOP EXAMPLE SLUG HERE --)/gi,
template: `${exampleSlug}`,
},
{
type: "modify",
path: `${contentDestinationPath}/content.tsx`,
pattern: /(-- PLOP EXAMPLE DEMO HERE --)/gi,
template: `${demoUrlName}`,
},
{
type: "modify",
path: `${contentDestinationPath}/content.tsx`,
pattern: /(-- PLOP EXAMPLE SOURCE HERE --)/gi,
template: `${exampleSourceUrlName}`,
},
{
type: "modify",
path: `${contentDestinationPath}/content.tsx`,
pattern: /(-- PLOP EXAMPLE CAMEL HERE --)/gi,
template: `${exampleCamel}`,
},
];
},
});
};