Skip to content

Commit

Permalink
Fix new-error command (#44720)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
hanneslund and kodiakhq[bot] committed Jan 9, 2023
1 parent c956484 commit 33d7870
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions plopfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module.exports = function (plop) {
plop.setHelper('toFileName', (str) => str.toLowerCase().replace(/ /g, '-'))
function getFileName(str) {
return str.toLowerCase().replace(/ /g, '-')
}

plop.setGenerator('test', {
description: 'Create a new test',
Expand Down Expand Up @@ -76,10 +78,11 @@ module.exports = function (plop) {
},
],
actions: function (data) {
const fileName = getFileName(data.urlPath)
return [
{
type: 'add',
path: `errors/{{ toFileName name }}.md`,
path: `errors/${fileName}.md`,
templateFile: `errors/template.txt`,
},
{
Expand All @@ -88,13 +91,13 @@ module.exports = function (plop) {
transform(fileContents, data) {
const manifestData = JSON.parse(fileContents)
manifestData.routes[0].routes.push({
title: '{{ toFileName name }}',
path: `/errors/{{ toFileName name }}.md`,
title: fileName,
path: `/errors/${fileName}.md`,
})
return JSON.stringify(manifestData, null, 2)
},
},
`Url for the error: https://nextjs.org/docs/messages/{{ toFileName name }}`,
`Url for the error: https://nextjs.org/docs/messages/${fileName}`,
]
},
})
Expand Down

0 comments on commit 33d7870

Please sign in to comment.