"""docs/tools/extract_all.py — 추출 한 명령(PLAN 478-1). TS → 파이썬 → 서버 주소 차례로 돌리고 함수 둘을 `docs/_data/functions.json` 한 벌로 합침 · 걸린 시간 출력. 부르기: `./venv/Scripts/python.exe docs/tools/extract_all.py` (ts-morph = `npm --prefix docs/tools install`). """ from __future__ import annotations import json import subprocess import sys import time from pathlib import Path ROOT = Path(__file__).resolve().parents[2] TOOLS = ROOT / "docs/tools" DATA = ROOT / "docs/_data" STEPS = [ ("ts", ["node", str(TOOLS / "extract_ts.mjs")]), ("py", [sys.executable, str(TOOLS / "extract_py.py")]), ("api", [sys.executable, "-W", "ignore", str(TOOLS / "extract_api.py")]), ] def load(name: str): return json.loads((DATA / name).read_text(encoding="utf-8")) def main() -> None: start = time.perf_counter() for name, cmd in STEPS: t = time.perf_counter() subprocess.run(cmd, cwd=ROOT, check=True) # noqa: S603 — 고정 명령 print(f" {name} {time.perf_counter() - t:.1f} s") functions = sorted( load("raw/functions_ts.json") + load("raw/functions_py.json"), key=lambda f: f["id"] ) (DATA / "functions.json").write_text( json.dumps(functions, ensure_ascii=False, indent=1) + "\n", encoding="utf-8" ) print( f"함수 {len(functions)} · 세션 칸 {len(load('session_keys.json'))} · " f"서버 주소 {len(load('api.json'))} · 등록부 {len(load('registry.json'))} · " f"모두 {time.perf_counter() - start:.1f} s" ) if __name__ == "__main__": main()