import * as DenoDoc from "./deno-doc.model.ts";
const decoder = new TextDecoder();const GlobalFilesSet = new Set();
export async function getDenoDoc( path?: string,): Promise<DenoDoc.RootDef[] | any> { if (GlobalFilesSet.has(path)) return undefined;
GlobalFilesSet.add(path);
const option = { cmd: [ Deno.execPath(), "doc", "--json", "--reload", ], stdout: "piped", stderr: "piped", };
if (path) { option.cmd.push(path); }
const process: Deno.Process<Deno.RunOptions> = Deno.run(option as any);
let killed = false;
const [out, errOut] = await Promise.all([ process.output(), process.stderrOutput(), ]);
const status = await process.status(); process.close(); if (!status.success) { if (killed) throw new Error("Parse timed out"); throw new Error(decoder.decode(errOut)); }
const result = JSON.parse(decoder.decode(out));
for (let i = 0; i < result.length; i++) { const object = result[i];
if (object.kind === "import" && !GlobalFilesSet.has(object.importDef.src)) { const src: string = object.importDef.src;
if (src.startsWith("http")) { GlobalFilesSet.add(src); } else { object.importDef.def = await getDenoDoc(src); } } }
return result;}