# ============================================================================== # Author: Simon-Pierre Boucher # File: scripts/build_frontend.py # Desc: Construit frontend/dist/index.html à partir du gabarit en injectant : # __ICONS__ — tracés SVG des marques (simple-icons, licence CC0) # __KA_TOKENS__ — ka/tokens.css (design system commun Groupe KA, # importé EN PREMIER dans le ) # __KA_ECO__ — ka/ecosystem.json (contacts, sites & mentions légales # du groupe : footer commun + page /contact) # ============================================================================== """Usage : python3 scripts/build_frontend.py Lit frontend/src/index.template.html + frontend/src/icons.json + frontend/src/ka/{tokens.css,ecosystem.json} et produit frontend/dist/index.html (remplacement des marqueurs __ICONS__, __KA_TOKENS__ et __KA_ECO__).""" from __future__ import annotations import json from pathlib import Path ROOT = Path(__file__).resolve().parent.parent SRC = ROOT / "frontend" / "src" KA = SRC / "ka" DIST = ROOT / "frontend" / "dist" def main() -> None: icons = json.loads((SRC / "icons.json").read_text(encoding="utf-8")) tokens = (KA / "tokens.css").read_text(encoding="utf-8") eco = json.loads((KA / "ecosystem.json").read_text(encoding="utf-8")) html = (SRC / "index.template.html").read_text(encoding="utf-8") for marker in ("__ICONS__", "__KA_TOKENS__", "__KA_ECO__"): if marker not in html: raise SystemExit(f"[crea-ka] marqueur manquant dans le gabarit : {marker}") html = html.replace("__ICONS__", json.dumps(icons, separators=(",", ":"))) html = html.replace("__KA_TOKENS__", tokens) html = html.replace("__KA_ECO__", json.dumps(eco, ensure_ascii=False, separators=(",", ":"))) DIST.mkdir(parents=True, exist_ok=True) (DIST / "index.html").write_text(html, encoding="utf-8") # Widget KA Agent (bulle de chat IA Groupe KA) — source perenne dans # frontend/src/, copie vers dist/ a chaque build (dist est regenere). (DIST / "ka-agent.js").write_bytes((SRC / "ka-agent.js").read_bytes()) (DIST / "ka-id.js").write_bytes((SRC / "ka-id.js").read_bytes()) print(f"[crea-ka] frontend construit → {DIST/'index.html'} " f"({len(html)//1024} Ko, {len(icons)} icônes, tokens ka-ui + écosystème injectés)") if __name__ == "__main__": main()