feat(init): task to generate manifest file (#1422)
This commit is contained in:
@@ -554,6 +554,8 @@ const config = {
|
||||
tasks: {
|
||||
check:
|
||||
"deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx",
|
||||
cli: "echo \"import '\\$fresh/src/dev/cli.ts'\" | deno run --unstable -A -",
|
||||
manifest: "deno task cli manifest $(pwd)",
|
||||
start: "deno run -A --watch=static/,routes/ dev.ts",
|
||||
build: "deno run -A dev.ts build",
|
||||
preview: "deno run -A main.ts",
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { join, toFileUrl } from "./deps.ts";
|
||||
import { manifest } from "./mod.ts";
|
||||
import { type FreshConfig } from "../server/mod.ts";
|
||||
|
||||
const args = Deno.args;
|
||||
|
||||
switch (args[0]) {
|
||||
case "manifest": {
|
||||
if (args[1]) {
|
||||
const CONFIG_TS_PATH = join(args[1], "fresh.config.ts");
|
||||
const url = toFileUrl(CONFIG_TS_PATH).toString();
|
||||
const config: FreshConfig = (await import(url)).default;
|
||||
await manifest(args[1], config?.router?.ignoreFilePattern);
|
||||
} else {
|
||||
console.error("Missing input for manifest command");
|
||||
Deno.exit(1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
console.error("Invalid command");
|
||||
Deno.exit(1);
|
||||
}
|
||||
}
|
||||
@@ -495,3 +495,61 @@ Deno.test("init - show help screen", async (t) => {
|
||||
assertStringIncludes(stdout, "Initialize a new Fresh project");
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "regenerate manifest",
|
||||
async fn(t) {
|
||||
const MANIFEST_FILENAME = "fresh.gen.ts";
|
||||
const tmpDirName = await Deno.makeTempDir();
|
||||
const manifestFilePath = path.join(tmpDirName, MANIFEST_FILENAME);
|
||||
|
||||
await t.step("execute init command", async () => {
|
||||
const cliProcess = new Deno.Command(Deno.execPath(), {
|
||||
args: [
|
||||
"run",
|
||||
"-A",
|
||||
"init.ts",
|
||||
tmpDirName,
|
||||
],
|
||||
stdin: "null",
|
||||
stdout: "null",
|
||||
});
|
||||
const { code } = await cliProcess.output();
|
||||
assertEquals(code, 0);
|
||||
});
|
||||
|
||||
let oldManifestContent: string;
|
||||
await t.step("store the contents of the manifest", async () => {
|
||||
oldManifestContent = await Deno.readTextFile(manifestFilePath);
|
||||
});
|
||||
|
||||
await t.step("delete the manifest", async () => {
|
||||
await Deno.remove(manifestFilePath);
|
||||
});
|
||||
|
||||
await t.step("regenerate the manifest", async () => {
|
||||
const cliProcess = new Deno.Command(Deno.execPath(), {
|
||||
args: [
|
||||
"task",
|
||||
"manifest",
|
||||
],
|
||||
cwd: tmpDirName,
|
||||
stdin: "null",
|
||||
stdout: "piped",
|
||||
stderr: "piped",
|
||||
});
|
||||
|
||||
const output = await cliProcess.output();
|
||||
|
||||
assertEquals(output.code, 0);
|
||||
});
|
||||
|
||||
await t.step("assert the old and new contents are equal", async () => {
|
||||
const newManifestContent = await Deno.readTextFile(manifestFilePath);
|
||||
assertEquals(oldManifestContent, newManifestContent);
|
||||
});
|
||||
|
||||
await retry(() => Deno.remove(tmpDirName, { recursive: true }));
|
||||
},
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user