feat: prevent default code on route

This commit is contained in:
Valerio Ageno
2024-06-04 20:29:36 +02:00
parent a4b2dd222d
commit 5ea209de0b
@@ -190,28 +190,6 @@ export async function routeGenerator(config = defaultConfig): Promise<void> {
removeUnderscores(removeLayoutSegments(node.path)) ?? '',
)
const routeCode = fs.readFileSync(node.fullPath, 'utf-8')
const escapedRoutePath = removeTrailingUnderscores(
node.routePath.replaceAll('$', '$$'),
)
let replaced = routeCode
if (!routeCode) {
replaced = [
`import { createFileRoute } from '@tanstack/react-router'`,
`export const Route = createFileRoute('${escapedRoutePath}')({
component: () => <div>Hello ${escapedRoutePath}!</div>
})`,
].join('\n\n')
if (replaced !== routeCode) {
console.log(`[emoticon] Updating ${node.fullPath}`)
await fsp.writeFile(node.fullPath, replaced)
}
}
if (node.parent) {
node.parent.children = node.parent.children ?? []
node.parent.children.push(node)