/* 840-2 기계 보기 셈 꼴 헬퍼 — common_util_machine_sheet.ts · common_util_formula_doc_cover.ts 를 그 자리에서 트랜스파일해 Node 로 돌림. * stdin = {문서들: {식 키: 식 문서}, 대상: [{식, 처음, 지금?, 덮음?, 개인, 직종?, 박음?: 값}]} * stdout = [{덮음: coverFrom(처음, 지금 | 처음), 줄: applyCover(처음, 지금 | 처음, 덮음 | coverFrom), 박음?: bindDoc(식, 박음)}] */ const fs = require("fs"); const path = require("path"); const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript")); const cache = new Map(); function load(at) { if (cache.has(at)) return cache.get(at); const js = ts.transpileModule(fs.readFileSync(at, "utf8"), { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, }).outputText; const box = { exports: {} }; cache.set(at, box.exports); const need = (p) => p.startsWith(".") ? load(path.resolve(path.dirname(at), `${p}.ts`)) : require(p); new Function("exports", "module", "require", js)(box.exports, box, need); return box.exports; } const root = path.join(__dirname, "..", "..", "common_util"); const cover = load(path.join(root, "common_util_formula_doc_cover.ts")); const sheet = load(path.join(root, "common_util_machine_sheet.ts")); const ask = JSON.parse(fs.readFileSync(0, "utf8")); const out = ask.대상.map((t) => { const doc = ask.문서들[t.식]; const parts = cover.partsOf(doc); const cur = t.지금 ?? t.처음; const made = sheet.coverFrom(parts, t.처음, cur, t.개인); const use = t.덮음 ?? made; const row = sheet.applyCover(parts, t.처음, cur, use, t.개인, t.직종 ?? {}); return { 덮음: made, 줄: row, ...(t.박음 ? { 박음: sheet.bindDoc(doc, t.박음) } : {}) }; }); process.stdout.write(JSON.stringify(out));