Files
ipass__ipass/scripts/collect-plugin-dist.sh
adminandClaude Opus 4.8 359a67b657 feat(gateway): wire plugin toggle (load+set_current+dispatch skip); short-name config keys (R19)
- postconfiguration loads <data_dir>/plugin-config.json into registry
- disabled plugins claim no /api routes (404 fallback); core never skipped
- data-seed keys + admin_prefix now Plugin::name() short names
- collect-plugin-dist.sh: normalize keys, resolve ipass-plugin-<short> dirs,
  emit <short>-admin.umd.js alias matching loader.ts protocol

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-09-24 20:05:48 +08:00

105 lines
4.8 KiB
Bash
Executable File
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 bash
# ============================================================================
# collect-plugin-dist.sh —— 收集管理台前端产物到可部署目录(Ruling 16)
#
# 背景:管理台已迁出本仓(ipass-ssw)。
# - 核心壳来自 ipass-core/www(index.html + assets)
# - 插件管理页是 UMD 产物,壳按
# /static/plugins/<name>/dist/<name>-admin.umd.js 动态加载
# (寻址约定见 ipass-core www/src/loader.ts;R19 起 <name> 统一为
# Plugin::name() 短名(domain/llm/apix),即 plugin-config.json 的键,
# 也即 /api/core/plugins 返回的 name)
# conf/nginx.conf 严禁把 /static/plugins/ alias 到 workspace 根——
# 会连带暴露各仓 data/*.json 等敏感文件(曾犯,同 ipass-sso 21c0f6f 修复)。
#
# 输出布局(默认 ASSEMBLY_DIR=build,本机 dev,build/ 已整体 gitignore):
# $ASSEMBLY_DIR/shell/ ← ../ipass-core/www/dist
# $ASSEMBLY_DIR/static-plugins/<name>/dist/ ← ../ipass-plugin-<name>/www/dist(仅 enabled)
# (<name> = R19 统一后的短名 domain/llm/apix;UMD 产物原名 plugin-<name>-admin.umd.js,
# 脚本另存一份 <name>-admin.umd.js 别名供壳按短名加载)
#
# 用法:
# bash scripts/collect-plugin-dist.sh # → build/(dev,配合 conf/nginx.conf)
# ASSEMBLY_DIR=deploy bash scripts/collect-plugin-dist.sh # docker build 前置收集
# ASSEMBLY_DIR=/usr/local/nginx SHELL_SUB=www sudo bash scripts/collect-plugin-dist.sh
# # 裸机部署:壳 → /usr/local/nginx/www,插件 → /usr/local/nginx/static-plugins
#
# 前置:ipass-core/www 与各启用插件仓 www 已 npm run build(dist 为最新)。
# 启用的插件清单读 data/plugin-config.json,缺失时回退 deploy/data-seed/ 模板。
# ============================================================================
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT="$(cd "$HERE/.." && pwd)"
IPASS_DIR="${IPASS_DIR:-$(cd "$ROOT/.." && pwd)}"
ASSEMBLY_DIR="${ASSEMBLY_DIR:-build}"
# 相对路径按仓根解析,绝对路径直接使用
case "$ASSEMBLY_DIR" in
/*) OUT="$ASSEMBLY_DIR" ;;
*) OUT="$ROOT/$ASSEMBLY_DIR" ;;
esac
SHELL_SUB="${SHELL_SUB:-shell}"
PLUGINS_SUB="static-plugins"
CONFIG="$ROOT/data/plugin-config.json"
[ -f "$CONFIG" ] || CONFIG="$ROOT/deploy/data-seed/plugin-config.json"
PYTHON="${PYTHON:-python3}"
command -v "$PYTHON" >/dev/null 2>&1 || { echo "!! 缺 python3(解析 plugin-config.json 用)" >&2; exit 1; }
# enabled 插件短名清单(R19 统一键 = Plugin::name(),如 domain;对应仓库 ipass-plugin-<短名>。
# 兼容旧 plugin- 前缀拼写:一律去掉前缀再映射目录)
PLUGINS="$("$PYTHON" - "$CONFIG" <<'PY'
import json, sys
cfg = json.load(open(sys.argv[1], encoding="utf-8"))
for name, p in cfg.get("plugins", {}).items():
if p.get("enabled"):
print(name.removeprefix("plugin-"))
PY
)"
# ---------------------------------------------------------------------------
# 1) 核心壳(ipass-core www dist)
# ---------------------------------------------------------------------------
SHELL_SRC="$IPASS_DIR/ipass-core/www/dist"
SHELL_OUT="$OUT/$SHELL_SUB"
[ -d "$SHELL_SRC" ] || { echo "!! core shell dist 缺失:$SHELL_SRC(先在 ipass-core/www 跑 npm run build)" >&2; exit 1; }
mkdir -p "$SHELL_OUT"
rsync -a --delete --exclude .gitkeep "$SHELL_SRC/" "$SHELL_OUT/"
echo "shell : $SHELL_SRC → $SHELL_OUT"
# ---------------------------------------------------------------------------
# 2) 启用插件的管理页 dist
# ---------------------------------------------------------------------------
PLUGINS_OUT="$OUT/$PLUGINS_SUB"
mkdir -p "$PLUGINS_OUT"
# 清空旧收集产物但保留 .gitkeep(如有 Dockerfile COPY 依赖目录存在)
find "$PLUGINS_OUT" -mindepth 1 -maxdepth 1 ! -name .gitkeep -exec rm -rf {} +
count=0
while IFS= read -r short; do
[ -n "$short" ] || continue
src="$IPASS_DIR/ipass-plugin-${short}/www/dist"
if [ ! -d "$src" ]; then
echo "!! $short:$src 缺失(先在 ipass-plugin-${short}/www 跑 npm run build),跳过" >&2
continue
fi
mkdir -p "$PLUGINS_OUT/$short/dist"
rsync -a --delete "$src/" "$PLUGINS_OUT/$short/dist/"
# 产物原文件名是 plugin-<短名>-admin.umd.js;壳按短名请求
# /static/plugins/<短名>/dist/<短名>-admin.umd.js(loader.ts 约定)→ 补一份短名别名
if [ ! -f "$PLUGINS_OUT/$short/dist/${short}-admin.umd.js" ] \
&& [ -f "$PLUGINS_OUT/$short/dist/plugin-${short}-admin.umd.js" ]; then
cp "$PLUGINS_OUT/$short/dist/plugin-${short}-admin.umd.js" \
"$PLUGINS_OUT/$short/dist/${short}-admin.umd.js"
fi
echo "plugin: $src → $PLUGINS_OUT/$short/dist"
count=$((count + 1))
done <<EOF
$PLUGINS
EOF
echo "完成:shell + ${count} 个插件 → $OUT"