#!/usr/bin/env bash # ============================================================================ # collect-plugin-dist.sh —— 收集管理台前端产物到可部署目录(Ruling 16) # # 背景:管理台已迁出本仓。 # - 核心壳来自 ipass-core/www(index.html + assets) # - 插件管理页是 UMD 产物,壳按 # /static/plugins//dist/-admin.umd.js 动态加载 # (寻址约定见 ipass-core www/src/loader.ts, 即 plugin-config.json 的键) # Docker 构建上下文只覆盖本仓,COPY 不到兄弟仓库,故本脚本先把产物聚合进 # $ASSEMBLY_DIR,再由 Dockerfile / nginx 静态目录消费。 # # 输出布局(默认 ASSEMBLY_DIR=deploy,供 docker build 前的准备步骤): # $ASSEMBLY_DIR/shell/ ← ../ipass-core/www/dist # $ASSEMBLY_DIR/static-plugins//dist/ ← ../ipass-/www/dist(仅 enabled) # # 用法: # bash scripts/collect-plugin-dist.sh # → deploy/ # ASSEMBLY_DIR=build bash scripts/collect-plugin-dist.sh # 本机 dev → build/(gitignored,壳目录名用 www-shell) # 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,缺失时回退 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:-deploy}" # 相对路径按仓根解析,绝对路径直接使用 case "$ASSEMBLY_DIR" in /*) OUT="$ASSEMBLY_DIR" ;; *) OUT="$ROOT/$ASSEMBLY_DIR" ;; esac # 壳目录名:deploy 布局用 shell/,dev(build) 布局用 www-shell/,可用 SHELL_SUB 覆盖 if [ -z "${SHELL_SUB:-}" ]; then if [ "$ASSEMBLY_DIR" = "build" ]; then SHELL_SUB="www-shell"; else SHELL_SUB="shell"; fi fi PLUGINS_SUB="static-plugins" CONFIG="$ROOT/data/plugin-config.json" [ -f "$CONFIG" ] || CONFIG="$ROOT/data-seed/plugin-config.json" PYTHON="${PYTHON:-python3}" command -v "$PYTHON" >/dev/null 2>&1 || { echo "!! 缺 python3(解析 plugin-config.json 用)" >&2; exit 1; } # enabled 插件名清单(如 plugin-sso;对应仓库目录 ipass-) 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) 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 name; do [ -n "$name" ] || continue src="$IPASS_DIR/ipass-${name}/www/dist" if [ ! -d "$src" ]; then echo "!! $name:$src 缺失(先在 ipass-${name}/www 跑 npm run build),跳过" >&2 continue fi mkdir -p "$PLUGINS_OUT/$name/dist" rsync -a --delete "$src/" "$PLUGINS_OUT/$name/dist/" echo "plugin: $src → $PLUGINS_OUT/$name/dist" count=$((count + 1)) done <