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

63 lines
1.9 KiB
Python
Raw Permalink 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 电子书小红书包(对齐 ebook/redmini:扁平,根目录唯一 index.html)。"""
from __future__ import annotations
import shutil
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SRC = ROOT / "tool"
OUT = ROOT / "release-book"
def main() -> int:
if OUT.exists():
shutil.rmtree(OUT, ignore_errors=True)
OUT.mkdir(parents=True)
parts = []
for name in ("book/book-data.js", "book/markdown.js", "book/xhs-bridge.js", "book-app.js"):
p = SRC / name
if not p.is_file():
# fallbacks used by assemble historically
alt = {
"book-app.js": SRC / "book-app.js",
"book/book-data.js": SRC / "book" / "book-data.js",
"book/markdown.js": SRC / "book" / "markdown.js",
"book/xhs-bridge.js": SRC / "book" / "xhs-bridge.js",
}[name]
p = alt
if not p.is_file():
print(f"missing {name}", file=sys.stderr)
return 1
parts.append(p.read_text(encoding="utf-8"))
html_src = SRC / "book.html"
css_src = SRC / "book-styles.css"
if not html_src.is_file() or not css_src.is_file():
print("missing book.html / book-styles.css", file=sys.stderr)
return 1
shutil.copy2(html_src, OUT / "index.html")
shutil.copy2(css_src, OUT / "styles.css")
(OUT / "app.js").write_text(
"/* bundled classic script for xhs ebook minitool */\n" + "\n".join(parts) + "\n",
encoding="utf-8",
)
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
print(f"assembled {OUT}")
for p in sorted(OUT.iterdir()):
if p.is_file():
print(f" {p.name}\t{p.stat().st_size}")
return 0
if __name__ == "__main__":
raise SystemExit(main())