"""Bundle the current Chapter 25 stdlib and methods example for offline browsing.""" from pathlib import Path import json deck = Path(__file__).resolve().parents[1] repo = deck.parents[1] source = repo / "chapter25/src/main/smp" paths = [source / "sys.smp", *sorted((source / "sys").rglob("*.smp"))] files = {path.relative_to(source).as_posix(): path.read_text(encoding="utf-8") for path in paths} bundle = {"origin": "chapter25/src/main/smp", "files": files, "methods": (deck / "demos/methods.smp").read_text(encoding="utf-8")} (deck / "stdlib.js").write_text( "/* Generated by tools/snapshot-library.py; local source snapshot. */\n" "window.REBASE.library = " + json.dumps(bundle, ensure_ascii=False, indent=2) + ";\n", encoding="utf-8", newline="\n") print(f"Bundled {len(files)} standard-library files and the methods example.")