/* 506-3 4-1 헬퍼 — B09 초안 [인쇄 미리보기] 단추를 Node 로 눌러 저장(DRAFT.save) 뒤 이동인지 표준출력 JSON 으로. */ const fs = require("fs"); const path = require("path"); const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript")); const calls = []; const DRAFT = { builders: {}, extend: [], panels: [], actions: [] }; const STUBS = { "@ui/ui_template_elements": { createButton: (opts) => ({ dataset: {}, onClick: opts.onClick }) }, "../../A00_Common/router": { navigateTo: (to) => calls.push(`go:${to}`) }, "../B09_Estimation_UI_Tabs": { DRAFT }, "./B09_Draft_Print_Route": { ROUTE: { path: "/b09-print" } }, }; const file = path.join(__dirname, "..", "..", "B09_Estimation", "draft", "B09_Draft_Print_UI.ts"); const js = ts.transpileModule(fs.readFileSync(file, "utf8"), { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, }).outputText; new Function("exports", "module", "require", js)({}, { exports: {} }, (r) => STUBS[r] ?? {}); const tick = () => new Promise((done) => setTimeout(done, 0)); (async () => { const button = DRAFT.actions[0](); const out = {}; DRAFT.save = async () => (calls.push("save"), true); button.onClick(); await tick(); out.saved = calls.splice(0); DRAFT.save = async () => (calls.push("save"), false); button.onClick(); await tick(); out.failed = calls.splice(0); process.stdout.write(JSON.stringify(out)); })();