From ceb30a6427f199d3e0c87fe61350ad017ca040e8 Mon Sep 17 00:00:00 2001 From: monoid Date: Fri, 6 Jan 2023 18:06:10 +0900 Subject: [PATCH] fix watch --- main.ts | 6 +++--- src/store/doc.ts | 12 ++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/main.ts b/main.ts index 23b69cd..32ad6ad 100644 --- a/main.ts +++ b/main.ts @@ -81,10 +81,10 @@ if (import.meta.main){ } ) .command("user", user_command) - .command("keyout", key_out_cmd) - ; + .command("keyout", key_out_cmd); + await cmd.parse(Deno.args); } else { await start(); -} +} \ No newline at end of file diff --git a/src/store/doc.ts b/src/store/doc.ts index 310b8c7..991b87d 100644 --- a/src/store/doc.ts +++ b/src/store/doc.ts @@ -1,3 +1,4 @@ +import { Index } from "../client_search.ts"; import { Doc, DocCollector } from "../collect.ts"; @@ -7,13 +8,16 @@ export const docCollector = new DocCollector( summaryOnly: true, }); -async function prepareDocs() { +export let docIndex: Index | undefined = undefined; + +export async function prepareDocs() { const docPath = Deno.env.get("COLLECT_DOC_PATH"); if (!docPath) { await docCollector.walkDir("."); - return docCollector.makeIndex({ + docIndex = docCollector.makeIndex({ watch: true }); + return docIndex; } try { @@ -30,11 +34,11 @@ async function prepareDocs() { } } - return docCollector.makeIndex({ + docIndex = docCollector.makeIndex({ watch: true, onUpdate: async () => { await Deno.writeTextFile(docPath, JSON.stringify(docCollector.getDocs())); } }); + return docIndex; } -export const docIndex = await prepareDocs();