- 새 파일 `M02_MasterTemplete_Labor_National`: 사전조합 `본뜬.전국자재` 를 자재목록 아래 표로(코드 「전국」 · 이름 · 규격 · 수량 · 단위 · 세 칸 글 · 「지역은 프로젝트에서」 · 금액 칸 비움 · 단추 없음) · 없으면 안 그림 · 셈 · 문서 꼴 · 저장 길 그대로 - 상세(`Labor_Detail`) 자재 칸에 부르는 줄 하나 · `Labor_Api` 본뜬 타입에 `전국자재` 칸 - 확인 창 자재 표 세 칸: 서버가 대상마다 `세칸`(`Material.marks` · 만들기와 같은 값)을 실음 → 전국-관급 줄 = 관급(옛 기본값 「사급」) - 시험: 전국 자재 줄 있는 것 · 없는 것 · 단추 없음 · 글 명사형 · 읽기 길 · 세 칸 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XWh5wNNycMkbwMpACz1rte
58 lines
2.3 KiB
JavaScript
58 lines
2.3 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 ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
|
|
|
|
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 cache = new Map();
|
|
function loadTs(file) {
|
|
const full = path.resolve(file);
|
|
if (cache.has(full)) return cache.get(full);
|
|
const js = ts.transpileModule(fs.readFileSync(full, "utf8"), {
|
|
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
|
}).outputText;
|
|
const box = { exports: {} };
|
|
cache.set(full, box.exports);
|
|
const localRequire = (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: () => () => ({}) });
|
|
};
|
|
new Function("exports", "module", "require", js)(box.exports, box, localRequire);
|
|
return box.exports;
|
|
}
|
|
|
|
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));
|