This commit is contained in:
Luca Casonato
2021-05-08 12:51:44 +02:00
parent 1f756a6d33
commit cfb99ef326
6 changed files with 93 additions and 6 deletions
+5 -2
View File
@@ -1,5 +1,6 @@
import { join } from "./deps.ts";
import { error } from "./error.ts";
import { routes } from "./routes.ts";
const help = `fresh init
@@ -10,10 +11,10 @@ To generate a project in the './foobar' subdirectory:
fresh init ./foobar
To generate a project in the current directory:
fresh init .
fresh init .
USAGE:
fresh init [OPTIONS] <DIRECTORY>
fresh init [OPTIONS] <DIRECTORY>
OPTIONS:
-h, --help Prints help information
@@ -143,4 +144,6 @@ fresh routes
join(directory, "README.md"),
README_MD,
);
await routes(directory);
}
+38 -3
View File
@@ -1,8 +1,43 @@
import { join, toFileUrl, walk } from "./deps.ts";
export async function routesSubcommand() {
const help = `fresh routes
Regenerate the route mapping for your fresh project.
To regenerate the mapping in the current directory:
fresh routes
To regenerate the mapping in the './foobar' subdirectory:
fresh routes ./foobar
USAGE:
fresh routes [OPTIONS] [DIRECTORY]
OPTIONS:
-h, --help Prints help information
`;
export interface Args {
help: boolean;
}
export async function routesSubcommand(rawArgs: Record<string, any>) {
const args: Args = {
help: !!rawArgs.help,
};
const directory: string | null = typeof rawArgs._[0] === "string"
? rawArgs._[0]
: Deno.cwd();
if (args.help) {
console.log(help);
Deno.exit(0);
}
await routes(directory);
}
export async function routes(directory: string) {
const files = [];
const pagesDir = join(Deno.cwd(), "./pages");
const pagesDir = join(Deno.cwd(), directory, "./pages");
const pagesUrl = new URL(pagesDir, "file:///");
const folder = walk(pagesDir, {
includeDirs: false,
@@ -30,5 +65,5 @@ setup([${
}], import.meta.url);
`;
await Deno.writeTextFile("./server.ts", output);
await Deno.writeTextFile(join(directory, "./server.ts"), output);
}
+1
View File
@@ -32,6 +32,7 @@ addEventListener("DOMContentLoaded", () => {
write: false,
bundle: true,
minify: true,
treeShaking: true,
platform: "neutral",
outfile: "",
jsxFactory: "h",
+1
View File
@@ -14,6 +14,7 @@ globalThis.performance = {
return new Date().getTime() - start;
},
};
// @deno-types="https://unpkg.com/esbuild-wasm@0.11.19/esm/browser.d.ts"
import * as esbuild from "https://gist.githubusercontent.com/lucacasonato/358c6b7e8198bfb2cf3d220e49fdcf5f/raw/3714cb0f59606eefc29ed0fea36d4cd93549938b/esbuild-wasm.js";
export { esbuild };
export { denoPlugin } from "https://raw.githubusercontent.com/lucacasonato/esbuild_deno_loader/fa2219c3df9494da6c33e3e4dffb1a33b5cc0345/mod.ts";