2026-06-12 11:41:03 -03:00
|
|
|
import fs from "node:fs";
|
|
|
|
|
import path from "node:path";
|
|
|
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
|
|
|
|
|
|
const scriptDir = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
|
export const defaultRouterFile = path.resolve(scriptDir, "../src/router.ts");
|
|
|
|
|
|
|
|
|
|
/** Strip `/src/app` prefix from generouted Path types — views live under src/app/, not src/pages/. */
|
|
|
|
|
export function fixGeneroutedRouterPaths(routerFile = defaultRouterFile) {
|
|
|
|
|
const content = fs.readFileSync(routerFile, "utf8");
|
2026-06-15 10:13:42 -03:00
|
|
|
const fixed = content
|
|
|
|
|
.replace(/`\/+src\/app\//g, "`/")
|
|
|
|
|
.replace(/`\/+src\/app`/g, "`/`")
|
|
|
|
|
.replace(/"\/+src\/app\//g, '"/')
|
|
|
|
|
.replace(/"\/+src\/app"/g, '"/"');
|
2026-06-12 11:41:03 -03:00
|
|
|
|
|
|
|
|
if (fixed !== content) {
|
|
|
|
|
fs.writeFileSync(routerFile, fixed);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isMain =
|
|
|
|
|
process.argv[1] && path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url));
|
|
|
|
|
|
|
|
|
|
if (isMain) {
|
|
|
|
|
fixGeneroutedRouterPaths();
|
|
|
|
|
}
|