fix watch

This commit is contained in:
monoid 2023-01-06 18:06:10 +09:00
parent 0a4a8e2009
commit ceb30a6427
2 changed files with 11 additions and 7 deletions

View File

@ -81,10 +81,10 @@ if (import.meta.main){
} }
) )
.command("user", user_command) .command("user", user_command)
.command("keyout", key_out_cmd) .command("keyout", key_out_cmd);
;
await cmd.parse(Deno.args); await cmd.parse(Deno.args);
} }
else { else {
await start(); await start();
} }

View File

@ -1,3 +1,4 @@
import { Index } from "../client_search.ts";
import { Doc, DocCollector } from "../collect.ts"; import { Doc, DocCollector } from "../collect.ts";
@ -7,13 +8,16 @@ export const docCollector = new DocCollector(
summaryOnly: true, summaryOnly: true,
}); });
async function prepareDocs() { export let docIndex: Index | undefined = undefined;
export async function prepareDocs() {
const docPath = Deno.env.get("COLLECT_DOC_PATH"); const docPath = Deno.env.get("COLLECT_DOC_PATH");
if (!docPath) { if (!docPath) {
await docCollector.walkDir("."); await docCollector.walkDir(".");
return docCollector.makeIndex({ docIndex = docCollector.makeIndex({
watch: true watch: true
}); });
return docIndex;
} }
try { try {
@ -30,11 +34,11 @@ async function prepareDocs() {
} }
} }
return docCollector.makeIndex({ docIndex = docCollector.makeIndex({
watch: true, watch: true,
onUpdate: async () => { onUpdate: async () => {
await Deno.writeTextFile(docPath, JSON.stringify(docCollector.getDocs())); await Deno.writeTextFile(docPath, JSON.stringify(docCollector.getDocs()));
} }
}); });
return docIndex;
} }
export const docIndex = await prepareDocs();