28 lines
1.3 KiB
Python
28 lines
1.3 KiB
Python
"""Build only the files served by the public demo."""
|
|
from pathlib import Path
|
|
import json
|
|
import re
|
|
import shutil
|
|
import sys
|
|
|
|
root = Path(__file__).resolve().parents[1]
|
|
out = Path(sys.argv[1])
|
|
out.mkdir(parents=True, exist_ok=True)
|
|
static = root / "game/static"
|
|
for name in ("app.js", "airfield.js", "cards.js", "demo-client.js", "style.css"):
|
|
shutil.copy(static / name, out)
|
|
index = (static / "index.html").read_text().replace('<html lang="ru">','<html lang="ru" data-demo>')
|
|
index = re.sub(r'<nav>.*?</nav>', '', index, flags=re.S)
|
|
index = re.sub(r'<a class="brand" href="#home"\s*>', '<span class="brand">', index)
|
|
index = re.sub(r'</small></a\s*>', '</small></span>', index)
|
|
(out / "index.html").write_text(index)
|
|
shutil.copy(root / "game/catalog.json", out)
|
|
for name in ("worker.js","cookie-worker.js","cookie-bridge.js"):
|
|
shutil.copy(root / "demo" / name, out)
|
|
shutil.copytree(root / "demo/vendor", out / "vendor", dirs_exist_ok=True)
|
|
for license_file in (root / "demo").glob("LICENSE-*"):
|
|
shutil.copy(license_file, out / (license_file.name + ".txt"))
|
|
files = {name:(root / "game" / name).read_text() for name in ("catalog.json","engine.py","strategy.py")}
|
|
files["local_game.py"] = (root / "demo/local_game.py").read_text()
|
|
(out / "rules.json").write_text(json.dumps(files, ensure_ascii=False))
|