/* 842-3 기계 인력 · 잡품 줄 헬퍼 — common_util_machine_crew.ts · common_util_formula_doc_cover.ts 를 트랜스파일해 Node 로 돌림. * stdin = {값들: [기계 값], 문서들: {키: 식 문서}, 대상: [{식, 값, 덮음?, 기계?}]} * stdout = {읽기: [crewView], 옛: [fromOld], 바탕: [rowEntry], 얹음: [coverDoc(식, {기계}, 덮음, rowEntry)]} */ 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 crew = load(path.join(root, "common_util_machine_crew.ts")); const cover = load(path.join(root, "common_util_formula_doc_cover.ts")); const ask = JSON.parse(fs.readFileSync(0, "utf8")); const out = { 읽기: ask.값들.map((v) => crew.crewView(v)), 옛: ask.값들.map((v) => crew.fromOld(v)), 바탕: ask.대상.map((t) => cover.rowEntry(ask.문서들[t.식], t.값)), 얹음: ask.대상.map((t) => { const doc = ask.문서들[t.식]; const given = { 기계: t.기계 ?? "M" }; return cover.coverDoc(doc, given, t.덮음 ? { [given.기계]: t.덮음 } : null, cover.rowEntry(doc, t.값)); }), }; process.stdout.write(JSON.stringify(out));