"""Write app/manifest.json: the files index.html hands to stlite, plus a cache-busting build id."""
import hashlib, json
from pathlib import Path
APP = Path(__file__).resolve().parents[1] / "app"
files = sorted(str(p.relative_to(APP)) for p in APP.rglob("*")
if p.is_file() and p.suffix in {".py", ".json", ".txt"} and "__pycache__" not in p.parts
and p.name != "manifest.json")
h = hashlib.sha256(b"".join((APP / f).read_bytes() for f in files)).hexdigest()[:12]
(APP / "manifest.json").write_text(json.dumps({"build": h, "requirements": [], "files": files}, indent=1))
print(f"{len(files)} files, build {h}")