- 헬퍼 동작 그대로(풀이 함수 본문은 옮겨 담음) · 제품 코드 안 고침 - 확인: 이 묶음 헬퍼를 쓰는 시험 428 개 전 417 통과 → 후 417 통과 (시험별 junit 대조 · 어긋남 0) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
49 lines
1.9 KiB
JavaScript
49 lines
1.9 KiB
JavaScript
/* M02 「전국」 자재 줄(361-2) 헬퍼 — `Labor_National.nationalRows` 를 트랜스파일해 Node 로 돌림 ·
|
|
* `el` 대역 = 나무 꼴 {tag, className, text, attrs, children} · stdin = {origin} · stdout = 나무 JSON. */
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const { makeLoader } = require("./helper_ts_stub_loader.cjs");
|
|
|
|
const ROOT = path.join(__dirname, "..", "..");
|
|
const el = (tag, o = {}) => ({ tag, ...o, children: o.children ?? [] });
|
|
const STUBS = {
|
|
"@ui/ui_template_elements": { el, createSelectField: () => ({ root: el("select") }) },
|
|
"@ui/ui_template_locale": { currentLanguageIndex: 0 },
|
|
"@config/config_frontend": { API_BASE_URL: "/api" },
|
|
};
|
|
const { loadTs } = makeLoader({
|
|
root: ROOT,
|
|
requireFor: (full) => (request) => {
|
|
if (STUBS[request]) return STUBS[request];
|
|
if (request.startsWith(".") && !request.endsWith(".css"))
|
|
return loadTs(`${path.resolve(path.dirname(full), request)}.ts`);
|
|
return new Proxy({}, { get: () => () => ({}) });
|
|
},
|
|
});
|
|
|
|
const input = JSON.parse(fs.readFileSync(0, "utf8"));
|
|
const national = loadTs(
|
|
path.join(ROOT, "M02_MasterTemplete", "M02_MasterTemplete_Labor_National.ts"),
|
|
);
|
|
const text = (n) => (n.text ?? "") + (n.children ?? []).map(text).join(" ");
|
|
const find = (n, tag) => [
|
|
...(n.tag === tag ? [n] : []),
|
|
...(n.children ?? []).flatMap((c) => find(c, tag)),
|
|
];
|
|
const out = input.origins.map((origin) => {
|
|
const got = national.nationalRows(origin);
|
|
const table = got.flatMap((n) => find(n, "table"))[0];
|
|
return {
|
|
count: got.length,
|
|
title: got[0]?.text ?? null,
|
|
heads: table ? find(table, "th").map((h) => h.text) : [],
|
|
rows: table
|
|
? find(table, "tr")
|
|
.slice(1)
|
|
.map((r) => r.children.map((c) => text(c).trim()))
|
|
: [],
|
|
buttons: got.flatMap((n) => [...find(n, "button"), ...find(n, "select")]).length,
|
|
};
|
|
});
|
|
process.stdout.write(JSON.stringify(out));
|