2022-01-06 16:45:04 +01:00
|
|
|
module.exports = function (plop) {
|
2023-01-25 01:47:48 +01:00
|
|
|
const toFileName = (str) => str.toLowerCase().replace(/ /g, '-')
|
|
|
|
plop.setHelper('toFileName', toFileName)
|
2022-01-06 16:45:04 +01:00
|
|
|
|
|
|
|
plop.setGenerator('test', {
|
|
|
|
description: 'Create a new test',
|
|
|
|
prompts: [
|
2022-12-19 20:08:50 +01:00
|
|
|
{
|
|
|
|
type: 'confirm',
|
|
|
|
name: 'appDir',
|
|
|
|
message: 'Is this test for the app directory?',
|
|
|
|
default: false,
|
|
|
|
},
|
2022-01-06 16:45:04 +01:00
|
|
|
{
|
|
|
|
type: 'input',
|
|
|
|
name: 'name',
|
|
|
|
message: 'Test name',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'list',
|
|
|
|
name: 'type',
|
|
|
|
message: 'Test type',
|
2022-02-21 19:09:32 +01:00
|
|
|
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' },
|
|
|
|
],
|
2022-01-06 16:45:04 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
actions: function (data) {
|
2023-01-06 21:36:47 +01:00
|
|
|
const appDirPath = data.appDir ? 'app-dir/' : ''
|
|
|
|
let templatePath = `test/${
|
|
|
|
data.type === 'unit' ? 'unit' : 'e2e'
|
|
|
|
}/${appDirPath}test-template`
|
|
|
|
let targetPath = `test/{{ type }}/${appDirPath}`
|
|
|
|
|
2022-01-06 16:45:04 +01:00
|
|
|
return [
|
|
|
|
{
|
2023-01-06 21:36:47 +01:00
|
|
|
type: 'addMany',
|
|
|
|
templateFiles: `${templatePath}/**/*`,
|
|
|
|
base: templatePath,
|
|
|
|
destination: targetPath,
|
2022-01-06 16:45:04 +01:00
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
plop.setGenerator('error', {
|
|
|
|
description: 'Create a new error document',
|
|
|
|
prompts: [
|
2022-09-16 23:54:58 +02:00
|
|
|
{
|
2023-01-25 01:47:48 +01:00
|
|
|
name: 'name',
|
2022-09-16 23:54:58 +02:00
|
|
|
type: 'input',
|
|
|
|
message: 'Url path with dashes. E.g. circular-structure',
|
|
|
|
},
|
2022-01-06 16:45:04 +01:00
|
|
|
{
|
|
|
|
name: 'title',
|
|
|
|
type: 'input',
|
2022-09-16 23:54:58 +02:00
|
|
|
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?',
|
2022-01-06 16:45:04 +01:00
|
|
|
},
|
|
|
|
],
|
2023-01-25 01:47:48 +01:00
|
|
|
actions: function ({ name }) {
|
2022-01-06 16:45:04 +01:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
type: 'add',
|
2023-01-25 01:47:48 +01:00
|
|
|
path: `errors/{{ toFileName name }}.md`,
|
2022-01-06 16:45:04 +01:00
|
|
|
templateFile: `errors/template.txt`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'modify',
|
|
|
|
path: 'errors/manifest.json',
|
2023-01-25 01:47:48 +01:00
|
|
|
transform(fileContents) {
|
2022-01-06 16:45:04 +01:00
|
|
|
const manifestData = JSON.parse(fileContents)
|
|
|
|
manifestData.routes[0].routes.push({
|
2023-01-25 01:47:48 +01:00
|
|
|
title: toFileName(name),
|
|
|
|
path: `/errors/${toFileName(name)}.md`,
|
2022-01-06 16:45:04 +01:00
|
|
|
})
|
|
|
|
return JSON.stringify(manifestData, null, 2)
|
|
|
|
},
|
|
|
|
},
|
2023-01-25 01:47:48 +01:00
|
|
|
`Url for the error: https://nextjs.org/docs/messages/${toFileName(
|
|
|
|
name
|
|
|
|
)}`,
|
2022-01-06 16:45:04 +01:00
|
|
|
]
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|