This commit is contained in:
2026-08-04 17:57:01 +08:00
parent 768fd4a3a9
commit f77034edd7
641 changed files with 26137 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
from __future__ import annotations
import json
import re
from pathlib import Path
ROOT = Path(__file__).resolve().parent
TEMPLATE = re.compile(r'<template\s+id="([^"]+)">\s*(.*?)\s*</template>', re.S)
for component in sorted(path for path in ROOT.iterdir() if path.is_dir()):
source = component / "index.html"
if not source.is_file():
continue
fragments = dict(TEMPLATE.findall(source.read_text(encoding="utf-8")))
if not fragments:
raise RuntimeError(f"No templates found in {source}")
key = f"{ROOT.name}/{component.name}/index.html"
payload = json.dumps(fragments, ensure_ascii=False, separators=(",", ":"))
script = (
"(() => {\n"
" window.componentRegistry ||= {};\n"
f" window.componentRegistry[{json.dumps(key)}] = {payload};\n"
"})();\n"
)
(component / "component.js").write_text(script, encoding="utf-8", newline="\n")
print(f"Updated {component.name}/component.js")