53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Assemble xhs/release/ (flat + relative paths, classic script only)."""
|
|
from __future__ import annotations
|
|
|
|
import shutil
|
|
import sys
|
|
from pathlib import Path
|
|
from subprocess import check_call
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
SRC = ROOT / "tool"
|
|
OUT = ROOT / "release"
|
|
|
|
|
|
def main() -> int:
|
|
check_call([sys.executable, str(ROOT / "scripts" / "sync_data.py")])
|
|
|
|
OUT.mkdir(parents=True, exist_ok=True)
|
|
|
|
data_js = (SRC / "nav-data.js").read_text(encoding="utf-8")
|
|
app_js = (SRC / "app.js").read_text(encoding="utf-8")
|
|
bundle = (
|
|
"/* bundled classic script for xhs minitool */\n"
|
|
+ data_js
|
|
+ "\n"
|
|
+ app_js
|
|
+ "\n"
|
|
)
|
|
|
|
shutil.copy2(SRC / "index.html", OUT / "index.html")
|
|
shutil.copy2(SRC / "styles.css", OUT / "styles.css")
|
|
(OUT / "app.js").write_text(bundle, encoding="utf-8")
|
|
|
|
icons_src = SRC / "icons"
|
|
icons_dst = OUT / "icons"
|
|
if icons_dst.exists():
|
|
shutil.rmtree(icons_dst, ignore_errors=True)
|
|
if icons_src.is_dir():
|
|
shutil.copytree(icons_src, icons_dst)
|
|
|
|
print(f"assembled {OUT}")
|
|
total = 0
|
|
for p in sorted(OUT.rglob("*")):
|
|
if p.is_file():
|
|
total += p.stat().st_size
|
|
print(f" {p.relative_to(OUT).as_posix()}\t{p.stat().st_size}")
|
|
print(f"total {total / 1024:.1f} KB")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|