Files
html-explainer/setup_env.sh
T
MohZhuang 2581e2c685 docs: 重构 README 并统一文档语言为中文
README 精简(中文 528 → 364 行,-31%;英文 552 → 390 行,-29%):
- 删除使用者不需要的深层细节,改为指向 references/ 与 SKILL.md:
  横向对比全表、八条契约表、project.json 逐字段说明、仓库目录树、B() 代码详解
- 第一定位改为「Agent Skill」,而不是「一条渲染流水线」
- 新增「安装」章:一句话安装 prompt + 九个智能体的技能目录对照表 + 环境要求
- 新增「参考思路与姊妹项目」:anything2explainer 与 html-video,并明确标注
  两者为不同作者的独立项目,本项目运行时不依赖其代码

文档语言统一为中文(README.en.md 除外):
CHANGELOG.md、CONTRIBUTING.md、THIRD_PARTY_NOTICES.md、PR/issue 模板、CI 注释。
许可证原文(MIT / Apache-2.0)与 GSAP 自带 README 属第三方逐字文本,未翻译。

跨平台可移植性修复(原先隐含 WorkBuddy 专属路径):
- peek_frame.mjs 的技能根兜底改为遍历各智能体技能目录
  (.workbuddy / .claude / .codex / .gemini / .cursor / .agents),已用隔离夹具正反验证
- setup_env.sh 标注哪几个候选是 WorkBuddy 托管路径
- SKILL.md 新增「跨 Agent 安装」章,安装路径不再写死单一平台

修正一处事实错误:THIRD_PARTY_NOTICES 原称两个方法来源项目「均为作者本人作品」,
与事实不符,已改为「他人独立项目」并补充来源链接。
2026-09-21 13:11:22 +08:00

140 lines
5.9 KiB
Bash
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 bash
# setup_env.sh —— html-explainer 一次性环境自检/安装(可反复跑)。
# 适配:Windows(Git Bash) / macOS / Linux。全部装用户级,不需要管理员。
#
# 用法:
# bash setup_env.sh # 自检,缺什么报告什么
# bash setup_env.sh --install # 自检 + 联网安装缺的依赖
#
# 依赖清单:
# Python ≥3.9 + edge-tts(7.2.8 钉死) numpy pillow imageio-ffmpeg
# Node ≥18(渲染器 .mjs)
# playwright-core(装在技能 node/ 下,纯 JS,可随技能打包带走)
# 浏览器:Chrome 或 Edge(几乎必有);都没有才下载 playwright chromium
# ffmpeg:PATH 有就用;没有则用 imageio-ffmpeg 的静态二进制(自动回退)
set -u
SKILL_ROOT="$(cd "$(dirname "$0")" && pwd)"
INSTALL=0
[ "${1:-}" = "--install" ] && INSTALL=1
# 计数口径:MISSING 表示「自检结束时仍缺的项」。
# 安装成功的项不计数 —— 所以先尝试装、装完再判定,不要在安装前就 miss。
MISSING=0
ok() { echo " ✓ $1"; }
miss() { echo " ✗ $1"; MISSING=$((MISSING + 1)); }
warn() { echo " ⚠ $1"; }
info() { echo " → $1"; }
echo "== html-explainer 环境自检 =="
# ---------- Python ----------
# 候选顺序:WorkBuddy 托管 venv(本机既有依赖,优先复用)→ 系统 python3 / python。
# 前两个是 WorkBuddy 专属路径,其它平台探不到就自动跳过,不影响使用。
PY=""
for c in "$HOME/.workbuddy/binaries/python/envs/default/Scripts/python.exe" \
"$HOME/.workbuddy/binaries/python/envs/default/bin/python" \
python3 python; do
if command -v "$c" >/dev/null 2>&1 || [ -x "$c" ]; then PY="$c"; break; fi
done
if [ -z "$PY" ]; then
miss "找不到 Python ≥3.9"
else
ok "Python: $PY ($("$PY" -V 2>&1))"
if ! "$PY" -c "import edge_tts, numpy, PIL, imageio_ffmpeg" >/dev/null 2>&1; then
if [ $INSTALL -eq 1 ]; then
info "pip 安装 Python 依赖(钉死 edge-tts==7.2.8:7.x 升级常有破坏性)…"
"$PY" -m pip install --user "edge-tts==7.2.8" numpy pillow imageio-ffmpeg >/dev/null 2>&1 \
|| "$PY" -m pip install "edge-tts==7.2.8" numpy pillow imageio-ffmpeg >/dev/null 2>&1 \
|| warn "pip 安装失败,请手动装"
fi
# 装完再判定
if "$PY" -c "import edge_tts, numpy, PIL, imageio_ffmpeg" >/dev/null 2>&1; then
ok "Python 依赖齐全(edge-tts / numpy / pillow / imageio-ffmpeg)"
else
miss "Python 依赖缺(edge-tts numpy pillow imageio-ffmpeg)"
fi
else
ok "Python 依赖齐全(edge-tts / numpy / pillow / imageio-ffmpeg)"
fi
fi
# ---------- Node ----------
node_major() { node -v 2>/dev/null | sed 's/^v//' | cut -d. -f1; }
if command -v node >/dev/null 2>&1; then
NV="$(node_major)"
if [ "${NV:-0}" -ge 18 ]; then ok "Node: $(node -v)"; else miss "Node ≥18 需要,当前 $(node -v)"; fi
else
# 兜底:WorkBuddy 托管的 Node(非标准安装,路径带版本号)。仅本机可用,其它平台跳过。
for d in "$HOME/.workbuddy/binaries/node/versions"/*/; do
if [ -x "$d/node.exe" ] || [ -x "$d/node" ]; then
export PATH="$d:$PATH"; ok "Node(托管): $(node -v)"; break
fi
done
command -v node >/dev/null 2>&1 || miss "找不到 Node ≥18(渲染器需要)"
fi
# ---------- playwright-core ----------
if [ ! -d "$SKILL_ROOT/node/node_modules/playwright-core" ] && [ $INSTALL -eq 1 ]; then
if command -v npm >/dev/null 2>&1; then
info "npm 安装 playwright-core(npmmirror 优先)…"
(cd "$SKILL_ROOT/node" && \
npm install playwright-core --registry https://registry.npmmirror.com --no-audit --no-fund) || \
(cd "$SKILL_ROOT/node" && npm install playwright-core --no-audit --no-fund) || \
warn "npm 安装失败(检查 npm/corepack 或换 registry)"
else
warn "没有 npm —— 无法自动安装 playwright-core"
fi
fi
# 装完再判定
if [ -d "$SKILL_ROOT/node/node_modules/playwright-core" ]; then
ok "playwright-core(技能内置 node/)"
else
miss "playwright-core 缺失"
fi
# ---------- 浏览器 ----------
BROWSER=""
for p in "/c/Program Files/Google/Chrome/Application/chrome.exe" \
"/c/Program Files (x86)/Google/Chrome/Application/chrome.exe" \
"$LOCALAPPDATA/Google/Chrome/Application/chrome.exe" \
"/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe" \
"/c/Program Files/Microsoft/Edge/Application/msedge.exe" \
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge" \
"/usr/bin/google-chrome" "/usr/bin/chromium" "/usr/bin/chromium-browser"; do
[ -f "$p" ] && BROWSER="$p" && break
done
if [ -n "$BROWSER" ]; then
ok "浏览器: $BROWSER(渲染直接用,无需下载)"
else
warn "没找到本机 Chrome/Edge —— 渲染时会回退 playwright 自带 chromium(首次 ~115MB 下载)"
if [ $INSTALL -eq 1 ]; then
echo " → 可预下载:npx playwright install chromium(或设 BROWSER_PATH 指向任一 Chromium 系浏览器)"
fi
fi
# ---------- ffmpeg ----------
if command -v ffmpeg >/dev/null 2>&1; then
ok "ffmpeg: $(command -v ffmpeg)"
elif [ -n "${PY:-}" ] && "$PY" -c "import imageio_ffmpeg" >/dev/null 2>&1; then
ok "ffmpeg 回退: imageio-ffmpeg 静态二进制($("$PY" -c "import imageio_ffmpeg;print(imageio_ffmpeg.get_ffmpeg_exe())" 2>/dev/null | head -1))"
else
miss "ffmpeg(PATH 或 imageio-ffmpeg 二者其一)"
fi
# ---------- GSAP ----------
if [ -f "$SKILL_ROOT/assets/gsap.min.js" ]; then
ok "GSAP 内置: assets/gsap.min.js(离线可用)"
else
miss "assets/gsap.min.js(被打包脚本删了?从 gsap npm 包 dist/ 恢复)"
fi
echo "----------------------------------------"
if [ $MISSING -eq 0 ]; then
echo "环境就绪 ✓(重跑加 --install 可自动装缺项)"
else
echo "缺 $MISSING 项 —— bash setup_env.sh --install 联网安装"
exit 1
fi