mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 20:32:05 +00:00
24 lines
802 B
TypeScript
24 lines
802 B
TypeScript
|
|
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");
|
||
|
|
const fixed = content.replace(/`\/+src\/app/g, "`").replace(/"\/+src\/app/g, '"/');
|
||
|
|
|
||
|
|
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();
|
||
|
|
}
|