/* 세월교 명세(표 04) · 월류 폭 ↔ 높이 계산 단위검증 헬퍼(PLAN 52-4) — `design_structure_spec.ts` · * `design_structure_ford.ts` · `design_structure_ford_calc.ts`(+ `fordSection` 이 든 B05 칸 조각)를 그 자리에서 * 트랜스파일해 Node 로 돌림. 결과 = JSON 한 벌. 인자 `names` 면 세월교 이름 표(정의 `종류.ford_bridge.이름`)만 냄. */ const fs = require("fs"); const path = require("path"); const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript")); const ROOT = path.join(__dirname, "..", ".."); const cache = new Map(); /** TS 한 파일을 CommonJS 로 — 상대 import 는 그 파일 자리 기준 · `@config/` 는 config 폴더 · .json 은 그대로. */ const load = (file) => { if (cache.has(file)) return cache.get(file); if (file.endsWith(".json")) return JSON.parse(fs.readFileSync(file, "utf8")); const js = ts.transpileModule(fs.readFileSync(file, "utf8"), { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, }).outputText; const box = { exports: {} }; cache.set(file, box.exports); const near = (m) => { const base = m.startsWith("@config/") ? path.join(ROOT, "config", m.slice(8)) : path.join(path.dirname(file), m); return load(base.endsWith(".json") ? base : `${base}.ts`); }; new Function("exports", "module", "require", js)(box.exports, box, near); cache.set(file, box.exports); return box.exports; }; const D = (f) => path.join(ROOT, "A00_Common", "design", f); const s = load(D("design_structure_spec.ts")); const { FORD_SPEC, withLegacyGuards } = load(D("design_structure_ford.ts")); const calc = load(D("design_structure_ford_calc.ts")); if (process.argv[2] === "names") { process.stdout.write(JSON.stringify(s.nameTable(FORD_SPEC))); process.exit(0); } const old = { pipe_kind: "파형강관", pipe_diameter_mm: 1000, pipe_count: 2, ford_width_m: 10, ford_height_m: 0.3, wing_in: "있음", wing_in_height_m: 1, wing_out: "없음", }; const legacy = withLegacyGuards(old); const state = s.readState(FORD_SPEC, legacy); const back = s.writeOptions(FORD_SPEC, state); const soil = JSON.parse(JSON.stringify(state)); soil.inlet[0].structure = "흙막이"; soil.outlet[0].structure = "날개벽"; const soilOut = s.writeOptions(FORD_SPEC, soil); const flows = [0.5, 2.54, 8]; const widths = [3, 5, 10, 20]; const table = flows.flatMap((q) => widths.map((b) => [q, b, calc.fordHeightM(q, b)])); const out = { containers: FORD_SPEC.containers.map((c) => [c.id, c.title, c.required]), items: FORD_SPEC.containers.map((c) => c.items.map((i) => [i.id, i.kind, i.key ?? null])), choices: FORD_SPEC.containers.map((c) => c.items.filter((i) => i.kind === "select").map((i) => s.choicesOf(i, {}).map((ch) => ch.label)), ), legacy: { inlet: legacy.inlet_type, outlet: legacy.outlet_type }, keepSoil: withLegacyGuards({ inlet_type: "흙막이", wing_in: "없음" }).inlet_type, b06Off: withLegacyGuards({ inlet_type: "날개벽", wing_in: "없음" }).inlet_type, b06On: withLegacyGuards({ inlet_type: "없음", wing_in: "있음" }).inlet_type, state, back, soilOut, links: FORD_SPEC.containers.map((c) => s.linkOf(c, 1)), keys: s.specKeys(FORD_SPEC), retired: FORD_SPEC.retired, table, none: [calc.fordHeightM(null, 10), calc.fordHeightM(2.54, 0)], hints: [ calc.fordHeightHint(2.54, 10), calc.fordHeightHint(2.54, 0), calc.fordHeightHint(null, 10), ], }; process.stdout.write(JSON.stringify(out));