import {Issue} from "./githubType.ts"; import {readAll} from "https://deno.land/std@0.135.0/streams/mod.ts" import {parse as argParse} from "https://deno.land/std@0.135.0/flags/mod.ts"; import {normalize, join as pathJoin, fromFileUrl} from "https://deno.land/std@0.135.0/path/mod.ts"; import * as Eta from "https://deno.land/x/eta/mod.ts"; function printOverall(issues: Issue[]){ const table = new Map(); issues.forEach((x)=>{ const category = x.title.split(":")[0]; if(!category) return; let c = table.get(category) if(!c){ c = [] table.set(category,c); } c.push(x); }) let index = 1; for (const [c,issues] of table) { console.log(`### 2.2.${index++} ${c} Operation\n`); let subIndex = 1; for (const i of issues) { console.log(`${subIndex++}. #${i.number} ${i.title}`); } console.log(""); } } function printContent(issues: Issue[]){ console.log(issues.map(i => `## (${i.number}) ${i.title}\n${i.body}`).join("\n\n")); } async function readContent(path?: string):Promise{ let content = "[]"; if(path){ content = await Deno.readTextFile(path); } else if(!Deno.isatty(Deno.stdin.rid)){ const decoder = new TextDecoder(undefined, {ignoreBOM:true}); const buf = await readAll(Deno.stdin); content = decoder.decode(buf); } return content; } if(import.meta.main){ 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); const c = await readContent(args.path); const issues = JSON.parse(c) as Issue[]; if(args.overall){ const c = await Eta.renderFile("overall.md.eta",{ issues: issues.sort((a,b)=>a.number-b.number) }); console.log(c); } else{ printContent(issues); } }