forked from vercel/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plopfile.mjs
109 lines (104 loc) · 3.13 KB
/
plopfile.mjs
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
export default function (plop) {
const transformName = (str) => {
return str.toLowerCase().replace(/ /g, '-')
}
// 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: 'App directory', value: 'app-directory' },
{ name: 'Edge Functions', value: 'edge-functions' },
{ name: 'Edge Middleware', value: 'edge-middleware' },
{ name: 'Solutions', value: 'solutions' },
{ name: 'Starter', value: 'starter' },
],
},
],
actions: (data) => {
const plopExampleName = transformName(data.name)
const plopPath = `${data.exampleScopeFolder}/${plopExampleName}`
const filesToAlwaysCopyOver = [
'README.md',
'tsconfig.json',
'.eslintrc.json',
'.gitignore',
'package.json',
'pnpm-lock.yaml',
'app/layout.tsx',
'app/page.tsx',
'postcss.config.js',
'tailwind.config.js',
'public/favicon.ico',
'turbo.json',
'vercel.json',
]
const actions = []
// Copy over basic files
filesToAlwaysCopyOver.forEach((file) => {
actions.push({
type: 'add',
path: `{{exampleScopeFolder}}/${plopExampleName}/${file}`,
templateFile: `plop-templates/example/${file}`,
})
})
// 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}`,
},
]
},
})
}