move where generated files end up
This commit is contained in:
parent
38b01a2c07
commit
73626cf31a
2 changed files with 11 additions and 10 deletions
|
@ -1,7 +1,7 @@
|
||||||
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";
|
import Pika from "../utils/instances/pika.ts";
|
||||||
|
|
||||||
const ROUTES_FILE = "routes.generated.ts";
|
const ROUTES_FILE = "routes.ts";
|
||||||
|
|
||||||
const S3inner = wait({
|
const S3inner = wait({
|
||||||
text: `Generating ${ROUTES_FILE}...`,
|
text: `Generating ${ROUTES_FILE}...`,
|
||||||
|
@ -39,7 +39,7 @@ async function readDir(dir: URL): Promise<PageRoute[]> {
|
||||||
).replace(/(\.ts)|(\.js)|(\/index(\.ts|\.js))/, "")
|
).replace(/(\.ts)|(\.js)|(\/index(\.ts|\.js))/, "")
|
||||||
.replace(/[\\/]+/g, '/')
|
.replace(/[\\/]+/g, '/')
|
||||||
|
|
||||||
const filePath = `./${relativePath}`;
|
const filePath = `../${relativePath}`;
|
||||||
const replaced = route.replace("/../src/routes", "")
|
const replaced = route.replace("/../src/routes", "")
|
||||||
let finalRoute = replaced;
|
let finalRoute = replaced;
|
||||||
if (replaced.includes('index') && !replaced.startsWith("/index"))
|
if (replaced.includes('index') && !replaced.startsWith("/index"))
|
||||||
|
@ -62,15 +62,15 @@ async function readDir(dir: URL): Promise<PageRoute[]> {
|
||||||
|
|
||||||
function createFile(routes: PageRoute[]): string {
|
function createFile(routes: PageRoute[]): string {
|
||||||
let string =
|
let string =
|
||||||
`// This File is Autogenerated by scripts/routes.ts
|
`// This File is generated by scripts/routes.ts
|
||||||
// Do not edit this File manually
|
// Do not edit this File manually
|
||||||
// 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) => (
|
${routes.map((route) => (
|
||||||
`import ${route.name} 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) => (`{ method: ${route.name}.method, handler: ${route.name}.handler, domains: ${route.name}.domains || undefined, route: "${route.route}" }`)).join(",\n ")}
|
const routes: PageRoute[] = [\n ${routes.map((route) => (`{ route: "${route.route}", method: ${route.name}.method, handler: ${route.name}.handler, domains: ${route.name}.domains || undefined }`)).join(",\n ")}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,14 +87,14 @@ async function write(folderwithroutes: string | URL, file: string | URL) {
|
||||||
const routes = await readDir(folderwithroutes)
|
const routes = await readDir(folderwithroutes)
|
||||||
const content = createFile(routes)
|
const content = createFile(routes)
|
||||||
|
|
||||||
await Deno.writeTextFile(`./src/${file}`, content)
|
await Deno.writeTextFile(`./src/generated/${file}`, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (import.meta.main) {
|
if (import.meta.main) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ensureFileSync(`./src/${ROUTES_FILE}`)
|
ensureFileSync(`./src/generated/${ROUTES_FILE}`)
|
||||||
await write('../src/routes', ROUTES_FILE)
|
await write('../src/routes', ROUTES_FILE)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { string } from "https://raw.githubusercontent.com/soremwar/deno_types/b5a146610e2c97c1612371fcf610b541f950ee73/prop-types/v15.7.2/prop-types.d.ts";
|
import { string } from "https://raw.githubusercontent.com/soremwar/deno_types/b5a146610e2c97c1612371fcf610b541f950ee73/prop-types/v15.7.2/prop-types.d.ts";
|
||||||
import { S3, S3Bucket } from "../deps.ts";
|
import { ensureFileSync, S3, S3Bucket } from "../deps.ts";
|
||||||
import { wait } from "../deps.ts"
|
import { wait } from "../deps.ts"
|
||||||
|
|
||||||
const S3inner = wait({
|
const S3inner = wait({
|
||||||
|
@ -44,7 +44,7 @@ for await (const obj of list) {
|
||||||
|
|
||||||
function createFile(files: S3File[]) {
|
function createFile(files: S3File[]) {
|
||||||
let string =
|
let string =
|
||||||
`// This File is Autogenerated by scripts/routes.ts
|
`// This File is generated by scripts/s3.ts
|
||||||
// Do not edit this File manually
|
// Do not edit this File manually
|
||||||
// run \`vr s3\` to regenerate this File
|
// run \`vr s3\` to regenerate this File
|
||||||
|
|
||||||
|
@ -69,7 +69,8 @@ async function write(files: S3File[], file: string | URL) {
|
||||||
if (import.meta.main) {
|
if (import.meta.main) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await write(Files, `s3.generated.ts`)
|
ensureFileSync(`./src/generated/s3.ts`)
|
||||||
|
await write(Files, `generated/s3.ts`)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
S3inner.fail()
|
S3inner.fail()
|
||||||
|
|
Loading…
Add table
Reference in a new issue