forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
plopfile.js
98 lines (96 loc) · 2.5 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
module.exports = function (plop) {
function getFileName(str) {
return str.toLowerCase().replace(/ /g, '-')
}
plop.setGenerator('test', {
description: 'Create a new test',
prompts: [
{
type: 'input',
name: 'name',
message: 'Test name',
},
{
type: 'list',
name: 'type',
message: 'Test type',
choices: [
{
name: 'e2e - Test "next dev" and "next build && next start"',
value: 'e2e',
},
{
name: 'production - Test "next build && next start"',
value: 'production',
},
{ name: 'development - Test "next dev"', value: 'development' },
{ name: 'unit - Test individual files', value: 'unit' },
],
},
],
actions: function (data) {
const fileName = getFileName(data.name)
return [
{
type: 'add',
templateFile: `test/${
data.type === 'unit' ? 'unit' : 'e2e'
}/example.txt`,
path: `test/{{type}}/${
data.type === 'unit'
? `${fileName}.test.ts`
: `${fileName}/index.test.ts`
}`,
},
]
},
})
plop.setGenerator('error', {
description: 'Create a new error document',
prompts: [
{
name: 'urlPath',
type: 'input',
message: 'Url path with dashes. E.g. circular-structure',
},
{
name: 'title',
type: 'input',
message: 'Title for the error. E.g. Circular Structure',
},
{
name: 'why',
type: 'input',
message: 'What caused the error to happen?',
},
{
name: 'fix',
type: 'input',
message: 'What are the possible ways to fix it?',
},
],
actions: function (data) {
const fileName = getFileName(data.urlPath)
return [
{
type: 'add',
path: `errors/${fileName}.md`,
templateFile: `errors/template.txt`,
},
{
type: 'modify',
path: 'errors/manifest.json',
transform(fileContents, data) {
const manifestData = JSON.parse(fileContents)
manifestData.routes[0].routes.push({
title: fileName,
path: `/errors/${fileName}.md`,
})
return JSON.stringify(manifestData, null, 2)
},
},
`Url for the error: https://nextjs.org/docs/messages/${fileName}`,
]
},
})
}