Unverified Commit 33d78704 authored by Hannes Bornö's avatar Hannes Bornö Committed by GitHub

Fix new-error command (#44720)

Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent c9564849
module.exports = function (plop) { module.exports = function (plop) {
plop.setHelper('toFileName', (str) => str.toLowerCase().replace(/ /g, '-')) function getFileName(str) {
return str.toLowerCase().replace(/ /g, '-')
}
plop.setGenerator('test', { plop.setGenerator('test', {
description: 'Create a new test', description: 'Create a new test',
...@@ -76,10 +78,11 @@ module.exports = function (plop) { ...@@ -76,10 +78,11 @@ module.exports = function (plop) {
}, },
], ],
actions: function (data) { actions: function (data) {
const fileName = getFileName(data.urlPath)
return [ return [
{ {
type: 'add', type: 'add',
path: `errors/{{ toFileName name }}.md`, path: `errors/${fileName}.md`,
templateFile: `errors/template.txt`, templateFile: `errors/template.txt`,
}, },
{ {
...@@ -88,13 +91,13 @@ module.exports = function (plop) { ...@@ -88,13 +91,13 @@ module.exports = function (plop) {
transform(fileContents, data) { transform(fileContents, data) {
const manifestData = JSON.parse(fileContents) const manifestData = JSON.parse(fileContents)
manifestData.routes[0].routes.push({ manifestData.routes[0].routes.push({
title: '{{ toFileName name }}', title: fileName,
path: `/errors/{{ toFileName name }}.md`, path: `/errors/${fileName}.md`,
}) })
return JSON.stringify(manifestData, null, 2) 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}`,
] ]
}, },
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment