feat: add arg outpath

This commit is contained in:
monoid 2022-04-20 22:24:47 +09:00
parent 38f82409bd
commit d2010834b7

View File

@ -47,21 +47,33 @@ async function readContent(path?: string):Promise<string>{
} }
if(import.meta.main){ if(import.meta.main){
const args = argParse(Deno.args);
const url = new URL(import.meta.url) const url = new URL(import.meta.url)
url.pathname = normalize(pathJoin(url.pathname,"..","template")); url.pathname = normalize(pathJoin(url.pathname,"..","template"));
const path = fromFileUrl(url); const path = fromFileUrl(url);
console.log(path);
Eta.configure({views: 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 c = await readContent(args.path);
const issues = JSON.parse(c) as Issue[]; const issues = JSON.parse(c) as Issue[];
let print: string = "";
if(args.overall){ 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) issues: issues.sort((a,b)=>a.number-b.number)
}); }) as string;
console.log(c);
} }
else{ else{
printContent(issues); printContent(issues);
} }
if(args.outpath){
Deno.writeTextFileSync(args.outpath,print);
}
else{
console.log(print);
}
} }