#!/usr/bin/env python3
"""将本目录下的 index.html + voice_app.js 打成单文件 dist/index.html。"""
from __future__ import annotations
import re
import shutil
import stat
from pathlib import Path
def main() -> None:
root = Path(__file__).resolve().parents[1]
index = root / "index.html"
app_js = root / "voice_app.js"
out_dir = root / "dist"
out_file = out_dir / "index.html"
if not index.is_file() or not app_js.is_file():
raise SystemExit(f"missing {index} or {app_js}")
html = index.read_text(encoding="utf-8")
js = app_js.read_text(encoding="utf-8")
pat = re.compile(
r'',
re.IGNORECASE,
)
if not pat.search(html):
raise SystemExit("index.html must contain ")
def _repl(_m):
return ""
inlined = pat.sub(_repl, html, count=1)
out_dir.mkdir(parents=True, exist_ok=True)
out_file.write_text(inlined, encoding="utf-8")
for name in ("start_http.sh", "start_http.bat"):
src = root / name
dst = out_dir / name
shutil.copy2(src, dst)
sh = out_dir / "start_http.sh"
sh.chmod(sh.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
print(f"wrote {out_file} (+ start_http.* in dist/)")
if __name__ == "__main__":
main()