diff --git a/07-start-frontend.sh b/07-start-frontend.sh index 29c7400..59d9b54 100755 --- a/07-start-frontend.sh +++ b/07-start-frontend.sh @@ -85,12 +85,38 @@ declare -A FE_PORT=( [build-down]=":8003" ) +declare -A FE_PORT_NUM=( + [pc]="5173" + [meetingh5]="5188" + [h5]="3003" + [cms]="8001" + [build-cms]="8002" + [build-down]="8003" +) + # 本机需 Electron 桌面客户端时:PC_ELECTRON=1 → yarn dev(需 GUI / libatk 等) if [[ "${PC_ELECTRON:-}" == "1" ]] || [[ "${PC_ELECTRON:-}" == "true" ]]; then FE_CMD[pc]="yarn dev" FE_PORT[pc]=":5173 (yarn dev + Electron)" fi +_check_fe_port_free() { + local name="$1" + local port="${FE_PORT_NUM[$name]}" + local pids + + pids="$(lsof -tiTCP:"$port" -sTCP:LISTEN 2>/dev/null || true)" + if [[ -n "$pids" ]]; then + error "$name 启动失败: 端口 $port 已被占用" + echo "占用进程:" + lsof -nP -iTCP:"$port" -sTCP:LISTEN 2>/dev/null || true + echo "" + echo "请先停止占用进程,例如:" + echo " lsof -ti :$port | xargs -r kill" + return 1 + fi +} + # ── 启动单个前端服务 ────────────────────────────────────────────────────────── _start_fe() { local name="$1" @@ -130,6 +156,8 @@ _start_fe() { return 1 fi + _check_fe_port_free "$name" || return 1 + info "启动 ${BOLD}$name${NC} ..." if [[ "$name" == "pc" ]]; then pc_ensure_wasm_assets