nomadro/apps/miniprogram/xhs/scripts/pack.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

57 lines
1.8 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
"""Pack release/ → dist zip. 强制:根目录有且仅有一个 index.html。"""
from __future__ import annotations
import sys
import zipfile
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
TOOL = ROOT / "release"
OUT = ROOT / "dist" / "youmin-nav-xhs-tool.zip"
def main() -> int:
out = Path(sys.argv[1]) if len(sys.argv) > 1 else OUT
out.parent.mkdir(parents=True, exist_ok=True)
if out.exists():
out.unlink()
files = sorted(p for p in TOOL.rglob("*") if p.is_file())
if not files:
print("release/ is empty — run: python scripts/assemble.py", file=sys.stderr)
return 1
root_index = TOOL / "index.html"
if not root_index.is_file():
print("FATAL: release/index.html missing", file=sys.stderr)
return 1
nested = [p for p in TOOL.rglob("index.html") if p != root_index]
if nested:
print(
"FATAL: nested index.html breaks XHS upload:",
[p.relative_to(TOOL).as_posix() for p in nested],
file=sys.stderr,
)
return 1
with zipfile.ZipFile(out, "w", compression=zipfile.ZIP_DEFLATED) as zf:
# 先写根 index.html,避免平台按字典序扫到子路径
zf.write(root_index, "index.html")
for p in files:
rel = p.relative_to(TOOL).as_posix()
if rel == "index.html":
continue
zf.write(p, rel)
names = zipfile.ZipFile(out).namelist()
assert "index.html" in names, names
assert not any(n != "index.html" and n.endswith("/index.html") for n in names), names
print(f"packed {out} ({out.stat().st_size / 1024:.1f} KB) entries={len(names)}")
print("zip root entries:", [n for n in names if "/" not in n])
return 0
if __name__ == "__main__":
raise SystemExit(main())