- 노선 추천 칸 [초기화] 단추 · 편집기 handler · /route/plan 의 initial_route(전처리 초기 노선) 걷음 - 아래 [초기화] = 마지막 추천 [적용] 노선(초기값 스냅샷 규칙 그대로) · B05 · B06 초안만 지움 - 시험 test_418_reset_cleanup · 옛 시험 단언 고침 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ji4nuyLVHcxrXWHTdb5nRD
103 lines
3.4 KiB
JavaScript
103 lines
3.4 KiB
JavaScript
/* 418 좌측 아래 [초기화] 헬퍼 — 진짜 `design_reset` · `b_page_state` 를 Node 로 돌려 남은 초안을
|
|
* 표준출력 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 calls = [];
|
|
const STUBS = {
|
|
"@ui/ui_template_elements": {
|
|
showConfirmDialog: async () => true,
|
|
showLoadingOverlay: () => {},
|
|
hideLoadingOverlay: () => {},
|
|
showToast: (message, kind) => calls.push(["toast", kind]),
|
|
},
|
|
"@ui/ui_template_locale": {
|
|
currentLanguageIndex: 0,
|
|
ui_locales: new Proxy({}, { get: (_, key) => [String(key)] }),
|
|
},
|
|
B05_Profile_Api_Fetch: {
|
|
resetRouteDesign: async () => calls.push(["resetRouteDesign"]),
|
|
clearRouteLatestCache: () => {},
|
|
},
|
|
B05_Profile_UI_Profile_Edit: { clearAlignmentDrafts: () => {} },
|
|
B06_Section_Section_Store: { invalidateSectionDetail: () => {} },
|
|
};
|
|
|
|
const cache = new Map();
|
|
const load = (file) => {
|
|
if (cache.has(file)) return cache.get(file);
|
|
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 stub = STUBS[m] ?? STUBS[path.basename(m)];
|
|
if (stub) return stub;
|
|
if (m.startsWith(".")) return load(path.join(path.dirname(file), `${m}.ts`));
|
|
throw new Error(`안 막은 import: ${m}`);
|
|
};
|
|
new Function("exports", "module", "require", js)(box.exports, box, near);
|
|
return box.exports;
|
|
};
|
|
|
|
class Store {
|
|
constructor() {
|
|
this.map = new Map();
|
|
}
|
|
get length() {
|
|
return this.map.size;
|
|
}
|
|
key(i) {
|
|
return [...this.map.keys()][i] ?? null;
|
|
}
|
|
getItem(k) {
|
|
return this.map.has(k) ? this.map.get(k) : null;
|
|
}
|
|
setItem(k, v) {
|
|
this.map.set(k, String(v));
|
|
}
|
|
removeItem(k) {
|
|
this.map.delete(k);
|
|
}
|
|
}
|
|
const session = new Store();
|
|
globalThis.window = { sessionStorage: session, localStorage: new Store() };
|
|
globalThis.location = { reload: () => calls.push(["reload"]) };
|
|
|
|
const state = load(path.join(ROOT, "A00_Common", "b_page_state.ts"));
|
|
const { resetDesign } = load(path.join(ROOT, "A00_Common", "design", "design_reset.ts"));
|
|
|
|
const P = "p418";
|
|
const OTHER = "q418";
|
|
const SEED = {
|
|
"b08-materials": { units: { a: 1 } },
|
|
"b08-hydro": { "0+020": { area: 1 } },
|
|
"b08-options": { soft_rock_pct: 10 },
|
|
"b08-milestone": { site: "x" },
|
|
"b09-estimation": { estimate: { b: 2 } },
|
|
"route-draft": { rev: 3 },
|
|
"std-cross": { width: 4 },
|
|
};
|
|
for (const [name, value] of Object.entries(SEED)) {
|
|
state.writeState(name, value, P);
|
|
state.writeState(name, value, OTHER);
|
|
}
|
|
state.writeState("crossdesign", { "0+020": "cut" }, P, 7); // 노선 범위 B06 초안
|
|
|
|
(async () => {
|
|
await resetDesign(P, 7);
|
|
const left = {};
|
|
for (const name of [...Object.keys(SEED), "crossdesign"]) {
|
|
left[name] = state.readState(name, P, name === "crossdesign" ? 7 : undefined);
|
|
}
|
|
const other = Object.fromEntries(Object.keys(SEED).map((n) => [n, state.readState(n, OTHER)]));
|
|
process.stdout.write(JSON.stringify({ left, other, seed: SEED, calls }));
|
|
})().catch((error) => {
|
|
process.stderr.write(String(error?.stack ?? error));
|
|
process.exit(1);
|
|
});
|