-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplopfile.ts
More file actions
132 lines (124 loc) · 4.76 KB
/
plopfile.ts
File metadata and controls
132 lines (124 loc) · 4.76 KB
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
130
131
132
import { NodePlopAPI } from 'plop';
import readdir from 'readdir-enhanced';
export default function (plop: NodePlopAPI) {
const transformName = (str) => {
return str.toLowerCase().replace(/ /g, '-')
}
function filterFn(stats) {
if (stats.isDirectory() || stats.path.match(/(^node_modules)/)) {
return false;
}
return true;
}
// create your generators here
plop.setGenerator('example', {
description: 'new example in repo',
prompts: [
{
type: 'input',
name: 'name',
message: 'Example name: ',
},
{
type: 'list',
name: 'exampleScopeFolder',
message: 'Scope (Example folder): ',
choices: [
{ name: 'Visual Embed', value: 'visual-embed' },
{ name: 'Rest APIs', value: 'rest-api' },
{ name: 'Solutions', value: 'solutions' },
{ name: 'Starter', value: 'starter' },
],
},
{
type: 'list',
name: 'language',
message: 'Language / Framework: ',
choices: [
{ name: 'React + TS', value: 'react-ts' },
{ name: 'Typescript (Web)', value: 'ts' },
{ name: 'Typescript (Node)', value: 'node' },
{ name: 'Python', value: 'python' },
{ name: 'Other', value: 'other' },
]
},
],
actions: (data) => {
if (!data) {
return [];
}
const plopExampleName = transformName(data.name)
const plopPath = `${data.exampleScopeFolder}/${plopExampleName}`
const templateDir = `utilities/plop-templates/${data.language}`
const actions: any[] = [];
readdir.sync(templateDir, { deep: true, filter: filterFn }).forEach((file) => {
actions.push({
type: 'add',
path: `{{exampleScopeFolder}}/${plopExampleName}/${file}`,
templateFile: `${templateDir}/${file}`,
})
actions.push({
type: 'modify',
path: `{{exampleScopeFolder}}/${plopExampleName}/${file}`,
pattern: /(-- PLOP EXAMPLE NAME HERE --)/gi,
template: `${plopExampleName}`,
});
actions.push({
type: 'modify',
path: `{{exampleScopeFolder}}/${plopExampleName}/${file}`,
pattern: /(-- PLOP PATH HERE --)/gi,
template: `${plopPath}`,
});
});
return actions;
// modify app/layout.tsx
actions.push({
type: 'modify',
path: `{{exampleScopeFolder}}/${plopExampleName}/app/layout.tsx`,
pattern: /(-- PLOP PATH HERE --)/gi,
template: `${plopPath}`,
})
actions.push({
type: 'modify',
path: `{{exampleScopeFolder}}/${plopExampleName}/app/layout.tsx`,
pattern: /(-- PLOP TITLE HERE --)/gi,
template: `${data.name}`,
})
return [
...actions,
// README.md
{
type: 'modify',
path: `{{exampleScopeFolder}}/${plopExampleName}/README.md`,
pattern: /(-- PLOP TITLE HERE --)/gi,
template: `${data.name}`,
},
{
type: 'modify',
path: `{{exampleScopeFolder}}/${plopExampleName}/README.md`,
pattern: /(-- PLOP EXAMPLE NAME HERE --)/gi,
template: `${plopExampleName}`,
},
{
type: 'modify',
path: `{{exampleScopeFolder}}/${plopExampleName}/README.md`,
pattern: /(-- PLOP PATH HERE --)/gi,
template: `${plopPath}`,
},
// package.json
{
type: 'modify',
path: `{{exampleScopeFolder}}/${plopExampleName}/package.json`,
pattern: /(-- PLOP EXAMPLE NAME HERE --)/gi,
template: `${plopExampleName}`,
},
{
type: 'modify',
path: `{{exampleScopeFolder}}/${plopExampleName}/app/page.tsx`,
pattern: /(-- PLOP TITLE HERE --)/gi,
template: `${data.name}`,
},
]
},
})
}