Redo Route generation, use Pika for unique import
This commit is contained in:
parent
1c1ec2f6bc
commit
7e8891f706
1 changed files with 7 additions and 3 deletions
|
@ -1,4 +1,6 @@
|
||||||
import { join, relative, ensureFileSync, wait, S3 } from "../deps.ts";
|
import { join, relative, ensureFileSync, wait, S3 } from "../deps.ts";
|
||||||
|
import Pika from "../utils/instances/pika.ts";
|
||||||
|
|
||||||
const ROUTES_FILE = "routes.generated.ts";
|
const ROUTES_FILE = "routes.generated.ts";
|
||||||
|
|
||||||
const S3inner = wait({
|
const S3inner = wait({
|
||||||
|
@ -7,6 +9,7 @@ const S3inner = wait({
|
||||||
})
|
})
|
||||||
|
|
||||||
interface PageRoute {
|
interface PageRoute {
|
||||||
|
name: string;
|
||||||
path: string;
|
path: string;
|
||||||
route: string;
|
route: string;
|
||||||
}
|
}
|
||||||
|
@ -47,6 +50,7 @@ async function readDir(dir: URL): Promise<PageRoute[]> {
|
||||||
S3inner.text = `Added ${finalRoute}`
|
S3inner.text = `Added ${finalRoute}`
|
||||||
|
|
||||||
routes.push({
|
routes.push({
|
||||||
|
name: Pika.gen("route"),
|
||||||
route: finalRoute,
|
route: finalRoute,
|
||||||
path: filePath,
|
path: filePath,
|
||||||
});
|
});
|
||||||
|
@ -63,10 +67,10 @@ function createFile(routes: PageRoute[]): string {
|
||||||
// run \`vr routes\` to regenerate this File
|
// run \`vr routes\` to regenerate this File
|
||||||
|
|
||||||
import PageRoute from "../utils/types/PageRoute.ts"
|
import PageRoute from "../utils/types/PageRoute.ts"
|
||||||
${routes.map((route, index) => (
|
${routes.map((route) => (
|
||||||
`import { method as method_${index}, handler as handler_${index} } from "${route.path.replace(/[\\/]+/g, '/')}";`).replace('./../src', ".")).join("\n")}
|
`import ${route.name} from "${route.path.replace(/[\\/]+/g, '/')}";`).replace('./../src', ".")).join("\n")}
|
||||||
|
|
||||||
const routes: PageRoute[] = [\n ${routes.map((route, index) => (`{ method: method_${index}, handler: handler_${index}, route: "${route.route}" }`)).join(",\n ")}
|
const routes: PageRoute[] = [\n ${routes.map((route) => (`{ method: ${route.name}.method, handler: ${route.name}.handler, domains: ${route.name}.domains || undefined, route: "${route.route}" }`)).join(",\n ")}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue