nomadro/apps/miniprogram/xhs/scripts/assemble.py
eric 69b0bd8224 Ship Taro H5 Vite build and Next-parity hub/nav/book/vip pages.
Switch miniprogram H5 to Vite for fast local compile; align portal pages and static icons for cross-machine continue.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-29 04:36:12 -05:00

60 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""Assemble xhs/release — nomadro 门户离线包(根目录唯一 index.html)。"""
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")])
if OUT.exists():
shutil.rmtree(OUT, ignore_errors=True)
OUT.mkdir(parents=True)
data_js = (SRC / "portal-data.js").read_text(encoding="utf-8")
app_js = (SRC / "app.js").read_text(encoding="utf-8")
bundle = (
"/* nomadro xhs offline bundle */\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"
if icons_src.is_dir():
shutil.copytree(icons_src, OUT / "icons")
nested = [p for p in OUT.rglob("index.html") if p != OUT / "index.html"]
if nested:
print("FATAL nested index.html:", nested, file=sys.stderr)
return 1
if "var PORTAL_DATA" not in bundle and "PORTAL_DATA" not in bundle:
print("FATAL missing PORTAL_DATA in bundle", file=sys.stderr)
return 1
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())