chore: improve manifest generator (#125)
Make the manifest generator output nicer: - routes are sorted - manifest is sent through `deno fmt`
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
// DO NOT EDIT. This file is generated by `fresh`.
|
// DO NOT EDIT. This file is generated by `fresh`.
|
||||||
// This file SHOULD be checked into source version control.
|
// This file SHOULD be checked into source version control.
|
||||||
// To update this file, run `fresh routes`.
|
// To update this file, run `fresh manifest`.
|
||||||
|
|
||||||
import * as $0 from "./routes/index.tsx";
|
import * as $0 from "./routes/index.tsx";
|
||||||
import * as $$0 from "./islands/Counter.tsx";
|
import * as $$0 from "./islands/Counter.tsx";
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// std
|
// std
|
||||||
export {
|
export {
|
||||||
|
extname,
|
||||||
join,
|
join,
|
||||||
resolve,
|
resolve,
|
||||||
toFileUrl,
|
toFileUrl,
|
||||||
|
|||||||
+28
-17
@@ -1,4 +1,5 @@
|
|||||||
import { join, resolve, toFileUrl, walk } from "./deps.ts";
|
import { extname, join, resolve, toFileUrl, walk } from "./deps.ts";
|
||||||
|
import { error } from "./error.ts";
|
||||||
|
|
||||||
const help = `fresh manifest
|
const help = `fresh manifest
|
||||||
|
|
||||||
@@ -67,26 +68,23 @@ export async function manifest(directory: string) {
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
routes.sort();
|
||||||
|
|
||||||
const islands = [];
|
const islands = [];
|
||||||
try {
|
try {
|
||||||
const islandsDir = join(directory, "./islands");
|
const islandsDir = join(directory, "./islands");
|
||||||
const islandsUrl = toFileUrl(islandsDir);
|
const islandsUrl = toFileUrl(islandsDir);
|
||||||
// TODO(lucacasonato): remove the extranious Deno.readDir when
|
for await (const entry of Deno.readDir(islandsDir)) {
|
||||||
// https://github.com/denoland/deno_std/issues/1310 is fixed.
|
if (entry.isDirectory) {
|
||||||
for await (const _ of Deno.readDir(islandsDir)) {
|
error(
|
||||||
// do nothing
|
`Found subdirectory '${entry.name}' in islands/. The islands/ folder must not contain any subdirectories.`,
|
||||||
}
|
|
||||||
const islandsFolder = walk(islandsDir, {
|
|
||||||
includeDirs: false,
|
|
||||||
includeFiles: true,
|
|
||||||
exts: ["tsx", "jsx", "ts", "js"],
|
|
||||||
});
|
|
||||||
for await (const entry of islandsFolder) {
|
|
||||||
if (entry.isFile) {
|
|
||||||
const file = toFileUrl(entry.path).href.substring(
|
|
||||||
islandsUrl.href.length,
|
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
if (entry.isFile) {
|
||||||
|
const ext = extname(entry.name);
|
||||||
|
if (![".tsx", ".jsx", ".ts", ".js"].includes(ext)) continue;
|
||||||
|
const path = join(islandsDir, entry.name);
|
||||||
|
const file = toFileUrl(path).href.substring(islandsUrl.href.length);
|
||||||
islands.push(file);
|
islands.push(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,10 +95,11 @@ export async function manifest(directory: string) {
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
islands.sort();
|
||||||
|
|
||||||
const output = `// DO NOT EDIT. This file is generated by \`fresh\`.
|
const output = `// DO NOT EDIT. This file is generated by \`fresh\`.
|
||||||
// This file SHOULD be checked into source version control.
|
// This file SHOULD be checked into source version control.
|
||||||
// To update this file, run \`fresh routes\`.
|
// To update this file, run \`fresh manifest\`.
|
||||||
|
|
||||||
${
|
${
|
||||||
routes.map((file, i) => `import * as $${i} from "./routes${file}";`).join(
|
routes.map((file, i) => `import * as $${i} from "./routes${file}";`).join(
|
||||||
@@ -133,5 +132,17 @@ export default manifest;
|
|||||||
|
|
||||||
const manifestPath = join(directory, "./fresh.gen.ts");
|
const manifestPath = join(directory, "./fresh.gen.ts");
|
||||||
await Deno.writeTextFile(manifestPath, output);
|
await Deno.writeTextFile(manifestPath, output);
|
||||||
console.log("Manifest generated and written to", manifestPath);
|
const proc = Deno.run({
|
||||||
|
cmd: [Deno.execPath(), "fmt", manifestPath],
|
||||||
|
stdin: "null",
|
||||||
|
stdout: "null",
|
||||||
|
stderr: "null",
|
||||||
|
});
|
||||||
|
await proc.status();
|
||||||
|
proc.close();
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`%cThe manifest has been generated for ${routes.length} routes and ${islands.length} islands.`,
|
||||||
|
"color: blue; font-weight: bold",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+33
-33
@@ -1,43 +1,43 @@
|
|||||||
// DO NOT EDIT. This file is generated by `fresh`.
|
// DO NOT EDIT. This file is generated by `fresh`.
|
||||||
// This file SHOULD be checked into source version control.
|
// This file SHOULD be checked into source version control.
|
||||||
// To update this file, run `fresh routes`.
|
// To update this file, run `fresh manifest`.
|
||||||
|
|
||||||
import * as $0 from "./routes/index.tsx";
|
import * as $0 from "./routes/[name].tsx";
|
||||||
import * as $1 from "./routes/params.tsx";
|
import * as $1 from "./routes/_404.tsx";
|
||||||
import * as $2 from "./routes/static.tsx";
|
import * as $2 from "./routes/_500.tsx";
|
||||||
import * as $3 from "./routes/intercept_args.tsx";
|
import * as $3 from "./routes/_app.tsx";
|
||||||
import * as $4 from "./routes/_render.ts";
|
import * as $4 from "./routes/_middleware.ts";
|
||||||
import * as $5 from "./routes/props/[id].tsx";
|
import * as $5 from "./routes/_render.ts";
|
||||||
import * as $6 from "./routes/failure.ts";
|
import * as $6 from "./routes/api/get_only.ts";
|
||||||
import * as $7 from "./routes/_middleware.ts";
|
import * as $7 from "./routes/books/[id].tsx";
|
||||||
import * as $8 from "./routes/books/[id].tsx";
|
import * as $8 from "./routes/failure.ts";
|
||||||
import * as $9 from "./routes/wildcard.tsx";
|
import * as $9 from "./routes/index.tsx";
|
||||||
import * as $10 from "./routes/api/get_only.ts";
|
import * as $10 from "./routes/intercept.tsx";
|
||||||
import * as $11 from "./routes/_500.tsx";
|
import * as $11 from "./routes/intercept_args.tsx";
|
||||||
import * as $12 from "./routes/intercept.tsx";
|
import * as $12 from "./routes/params.tsx";
|
||||||
import * as $13 from "./routes/_404.tsx";
|
import * as $13 from "./routes/props/[id].tsx";
|
||||||
import * as $14 from "./routes/[name].tsx";
|
import * as $14 from "./routes/static.tsx";
|
||||||
import * as $15 from "./routes/_app.tsx";
|
import * as $15 from "./routes/wildcard.tsx";
|
||||||
import * as $$0 from "./islands/Test.tsx";
|
import * as $$0 from "./islands/Test.tsx";
|
||||||
|
|
||||||
const manifest = {
|
const manifest = {
|
||||||
routes: {
|
routes: {
|
||||||
"./routes/index.tsx": $0,
|
"./routes/[name].tsx": $0,
|
||||||
"./routes/params.tsx": $1,
|
"./routes/_404.tsx": $1,
|
||||||
"./routes/static.tsx": $2,
|
"./routes/_500.tsx": $2,
|
||||||
"./routes/intercept_args.tsx": $3,
|
"./routes/_app.tsx": $3,
|
||||||
"./routes/_render.ts": $4,
|
"./routes/_middleware.ts": $4,
|
||||||
"./routes/props/[id].tsx": $5,
|
"./routes/_render.ts": $5,
|
||||||
"./routes/failure.ts": $6,
|
"./routes/api/get_only.ts": $6,
|
||||||
"./routes/_middleware.ts": $7,
|
"./routes/books/[id].tsx": $7,
|
||||||
"./routes/books/[id].tsx": $8,
|
"./routes/failure.ts": $8,
|
||||||
"./routes/wildcard.tsx": $9,
|
"./routes/index.tsx": $9,
|
||||||
"./routes/api/get_only.ts": $10,
|
"./routes/intercept.tsx": $10,
|
||||||
"./routes/_500.tsx": $11,
|
"./routes/intercept_args.tsx": $11,
|
||||||
"./routes/intercept.tsx": $12,
|
"./routes/params.tsx": $12,
|
||||||
"./routes/_404.tsx": $13,
|
"./routes/props/[id].tsx": $13,
|
||||||
"./routes/[name].tsx": $14,
|
"./routes/static.tsx": $14,
|
||||||
"./routes/_app.tsx": $15,
|
"./routes/wildcard.tsx": $15,
|
||||||
},
|
},
|
||||||
islands: {
|
islands: {
|
||||||
"./islands/Test.tsx": $$0,
|
"./islands/Test.tsx": $$0,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// DO NOT EDIT. This file is generated by `fresh`.
|
// DO NOT EDIT. This file is generated by `fresh`.
|
||||||
// This file SHOULD be checked into source version control.
|
// This file SHOULD be checked into source version control.
|
||||||
// To update this file, run `fresh routes`.
|
// To update this file, run `fresh manifest`.
|
||||||
|
|
||||||
import * as $0 from "./routes/index.tsx";
|
import * as $0 from "./routes/index.tsx";
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -1,18 +1,18 @@
|
|||||||
// DO NOT EDIT. This file is generated by `fresh`.
|
// DO NOT EDIT. This file is generated by `fresh`.
|
||||||
// This file SHOULD be checked into source version control.
|
// This file SHOULD be checked into source version control.
|
||||||
// To update this file, run `fresh routes`.
|
// To update this file, run `fresh manifest`.
|
||||||
|
|
||||||
import * as $0 from "./routes/_render.ts";
|
import * as $0 from "./routes/_render.ts";
|
||||||
import * as $1 from "./routes/gfm.css.ts";
|
import * as $1 from "./routes/docs/[...slug].tsx";
|
||||||
import * as $2 from "./routes/docs/[...slug].tsx";
|
import * as $2 from "./routes/gfm.css.ts";
|
||||||
import * as $3 from "./routes/index.tsx";
|
import * as $3 from "./routes/index.tsx";
|
||||||
import * as $$0 from "./islands/Counter.tsx";
|
import * as $$0 from "./islands/Counter.tsx";
|
||||||
|
|
||||||
const manifest = {
|
const manifest = {
|
||||||
routes: {
|
routes: {
|
||||||
"./routes/_render.ts": $0,
|
"./routes/_render.ts": $0,
|
||||||
"./routes/gfm.css.ts": $1,
|
"./routes/docs/[...slug].tsx": $1,
|
||||||
"./routes/docs/[...slug].tsx": $2,
|
"./routes/gfm.css.ts": $2,
|
||||||
"./routes/index.tsx": $3,
|
"./routes/index.tsx": $3,
|
||||||
},
|
},
|
||||||
islands: {
|
islands: {
|
||||||
|
|||||||
Reference in New Issue
Block a user