From d2010834b793541d7a48e397317bfebf7fb09e14 Mon Sep 17 00:00:00 2001 From: monoid Date: Wed, 20 Apr 2022 22:24:47 +0900 Subject: [PATCH] feat: add arg outpath --- tools/printDocument.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tools/printDocument.ts b/tools/printDocument.ts index 8b0d5b5..aa65fac 100644 --- a/tools/printDocument.ts +++ b/tools/printDocument.ts @@ -47,21 +47,33 @@ async function readContent(path?: string):Promise{ } if(import.meta.main){ + const args = argParse(Deno.args); + const url = new URL(import.meta.url) url.pathname = normalize(pathJoin(url.pathname,"..","template")); const path = fromFileUrl(url); - console.log(path); Eta.configure({views: path}); - let args = argParse(Deno.args); + + if(typeof args.path !== "string"){ + console.log("Please provide a path to the json file."); + Deno.exit(1); + } const c = await readContent(args.path); const issues = JSON.parse(c) as Issue[]; + + let print: string = ""; if(args.overall){ - const c = await Eta.renderFile("overall.md.eta",{ + print = await Eta.renderFile("overall.md.eta",{ issues: issues.sort((a,b)=>a.number-b.number) - }); - console.log(c); + }) as string; } else{ printContent(issues); } + if(args.outpath){ + Deno.writeTextFileSync(args.outpath,print); + } + else{ + console.log(print); + } } \ No newline at end of file