Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Fix new-error command" #45221

Merged
merged 4 commits into from
Jan 25, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions plopfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = function (plop) {
function getFileName(str) {
return str.toLowerCase().replace(/ /g, '-')
}
const toFileName = (str) => str.toLowerCase().replace(/ /g, '-')
plop.setHelper('toFileName', toFileName)

plop.setGenerator('test', {
description: 'Create a new test',
Expand Down Expand Up @@ -57,7 +56,7 @@ module.exports = function (plop) {
description: 'Create a new error document',
prompts: [
{
name: 'urlPath',
name: 'name',
type: 'input',
message: 'Url path with dashes. E.g. circular-structure',
},
Expand All @@ -77,27 +76,28 @@ module.exports = function (plop) {
message: 'What are the possible ways to fix it?',
},
],
actions: function (data) {
const fileName = getFileName(data.urlPath)
actions: function ({ name }) {
return [
{
type: 'add',
path: `errors/${fileName}.md`,
path: `errors/{{ toFileName name }}.md`,
templateFile: `errors/template.txt`,
},
{
type: 'modify',
path: 'errors/manifest.json',
transform(fileContents, data) {
transform(fileContents) {
const manifestData = JSON.parse(fileContents)
manifestData.routes[0].routes.push({
title: fileName,
path: `/errors/${fileName}.md`,
title: toFileName(name),
path: `/errors/${toFileName(name)}.md`,
})
return JSON.stringify(manifestData, null, 2)
},
},
`Url for the error: https://nextjs.org/docs/messages/${fileName}`,
`Url for the error: https://nextjs.org/docs/messages/${toFileName(
name
)}`,
]
},
})
Expand Down