/* 박스암거 명세 단위검증 헬퍼(PLAN 52-2) — `design_structure_spec.ts` · `design_structure_box.ts` 를 * 그 자리에서 트랜스파일해 Node 로 돌림(꼴만 import). 결과 = JSON 한 벌. * 인자 `names` 면 박스암거 이름 표(정의 `종류.box_culvert.이름`)만 냄. */ const fs = require("fs"); const path = require("path"); const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript")); const ROOT = path.join(__dirname, "..", ".."); const load = (file) => { const src = fs.readFileSync(path.join(ROOT, "A00_Common", "design", file), "utf8"); const js = ts.transpileModule(src, { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, }).outputText; const box = { exports: {} }; new Function("exports", "module", "require", js)(box.exports, box, require); return box.exports; }; const s = load("design_structure_spec.ts"); const b = load("design_structure_box.ts"); const SPEC = b.BOX_SPEC; if (process.argv[2] === "names") { process.stdout.write(JSON.stringify(s.nameTable(SPEC))); process.exit(0); } /** 화면이 하는 차례 그대로 — 옛 값 정리 → 명세 읽기 → 본체 칸 되찾기 → 저장 옵션. */ const roundTrip = (options, edit) => { const state = s.readState(SPEC, b.boxOptionsIn(options)); Object.assign(state.body[0], b.bodyOf(options)); edit?.(state); return { state, out: { ...s.writeOptions(SPEC, state), ...b.bodyOptions(state.body[0]) } }; }; const body = SPEC.containers.find((c) => c.id === "body"); const width = body.items.find((i) => i.id === "width"); const old = { body_width_m: 3, body_height_m: 2.5, wing_in: "있음", wing_in_length_m: 2 }; const out = { containers: SPEC.containers.map((c) => [c.id, c.title, c.required]), links: SPEC.containers.map((c) => s.linkOf(c, 1)), sizes: body.items[0].choices.map((c) => c.value), structures: SPEC.containers[1].items[0].choices.map((c) => c.value), customHidden: s.branchOf(width, { size: "2.0×2.0" }), customShown: s.branchOf(width, { size: "사용자 입력" }), old: roundTrip(old), preset: roundTrip({ body_width_m: 2, body_height_m: 2, wing_out: "없음" }), toPreset: roundTrip(old, (st) => { st.body[0].size = "3.0×3.0"; st.outlet[0].structure = "흙막이"; }), toCustom: roundTrip({ body_width_m: 2, body_height_m: 2 }, (st) => { st.body[0].size = "사용자 입력"; st.body[0].width = "2.4"; st.body[0].height = "1.8"; }), blank: roundTrip({}), keys: s.specKeys(SPEC), retired: SPEC.retired, }; process.stdout.write(JSON.stringify(out));