nomadro/apps/miniprogram/xhs/scripts/pack.py
eric 1d3e513ae2 Ship Douyin tt/ miniprogram: offline reader, clipboard privacy, README.
Add apps/miniprogram/tt as a standalone Douyin app with official usePrivacyCheck + tt.showModal/setClipboardData flow, single-chapter offline reader, and document console privacy setup for clipboard.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-30 15:17:52 +08:00

64 lines
2.1 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" / "nomadro-xhs-portal.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
file_entries = [n for n in names if not n.endswith("/")]
if len(file_entries) > 200:
print(
f"FATAL: zip has {len(file_entries)} files > 200 (创服平台上限)",
file=sys.stderr,
)
return 1
print(f"packed {out} ({out.stat().st_size / 1024:.1f} KB) entries={len(file_entries)}")
print("zip root entries:", [n for n in names if "/" not in n.rstrip("/")])
return 0
if __name__ == "__main__":
raise SystemExit(main())