From abc281b49b63f5cc5ddbf5ce976b0bac5d4c32c6 Mon Sep 17 00:00:00 2001 From: david Date: Tue, 28 Jul 2026 14:43:56 +0800 Subject: [PATCH] chore(dev): add platform debug runner --- scripts/run_platform.sh | 96 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100755 scripts/run_platform.sh diff --git a/scripts/run_platform.sh b/scripts/run_platform.sh new file mode 100755 index 0000000..755ae67 --- /dev/null +++ b/scripts/run_platform.sh @@ -0,0 +1,96 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" +BACKEND_DIR="${PROJECT_ROOT}/backend/api" +FRONTEND_DIR="${PROJECT_ROOT}/frontend/platform_admin" + +BACKEND_PID="" +FRONTEND_PID="" +CLEANED_UP=0 +RUNTIME_CONFIG_ROOT="" + +cleanup() { + if [[ "${CLEANED_UP}" -eq 1 ]]; then + return + fi + CLEANED_UP=1 + + trap - EXIT INT TERM + for pid in "${BACKEND_PID}" "${FRONTEND_PID}"; do + if [[ -n "${pid}" ]] && kill -0 "${pid}" 2>/dev/null; then + kill "${pid}" 2>/dev/null || true + fi + done + for pid in "${BACKEND_PID}" "${FRONTEND_PID}"; do + if [[ -n "${pid}" ]]; then + wait "${pid}" 2>/dev/null || true + fi + done + if [[ -n "${RUNTIME_CONFIG_ROOT}" ]]; then + rm -f "${RUNTIME_CONFIG_ROOT}/etc/heqi_dev.yaml" + rmdir "${RUNTIME_CONFIG_ROOT}/etc" "${RUNTIME_CONFIG_ROOT}" 2>/dev/null || true + fi +} + +require_command() { + if ! command -v "$1" >/dev/null 2>&1; then + echo "缺少命令:$1" >&2 + exit 1 + fi +} + +require_command go +require_command pnpm + +if [[ ! -d "${FRONTEND_DIR}/node_modules" ]]; then + echo "前端依赖尚未安装,请先运行:cd ${FRONTEND_DIR} && pnpm install" >&2 + exit 1 +fi + +export BSM_RuntimeMode="${BSM_RuntimeMode:-dev}" +export BSM_JwtSecretKey="${BSM_JwtSecretKey:-local-dev-key-16}" +export VITE_API_BASE_URL="${VITE_API_BASE_URL:-http://localhost:12426/heqi/platform/v1}" + +if [[ -z "${BSM_Prefix:-}" ]]; then + RUNTIME_CONFIG_ROOT="$(mktemp -d "${TMPDIR:-/tmp}/heqi-platform.XXXXXX")" + mkdir -p "${RUNTIME_CONFIG_ROOT}/etc" + cp "${BACKEND_DIR}/etc/platform_dev.yaml" "${RUNTIME_CONFIG_ROOT}/etc/heqi_dev.yaml" + export BSM_Prefix="${RUNTIME_CONFIG_ROOT}" +fi + +trap cleanup EXIT INT TERM + +echo "启动平台后端:http://localhost:12426/heqi/platform/v1" +( + cd "${BACKEND_DIR}" + exec go run ./cmd/main/main.go +) & +BACKEND_PID=$! + +echo "启动平台前端:http://localhost:5173" +( + cd "${FRONTEND_DIR}" + exec pnpm exec vite --config ./config/vite.config.ts --host 0.0.0.0 +) & +FRONTEND_PID=$! + +echo "前后端调试服务已启动,按 Ctrl+C 同时停止。" + +while true; do + if ! kill -0 "${BACKEND_PID}" 2>/dev/null; then + status=0 + wait "${BACKEND_PID}" || status=$? + echo "平台后端已退出(状态码:${status}),正在停止前端。" >&2 + exit "${status}" + fi + if ! kill -0 "${FRONTEND_PID}" 2>/dev/null; then + status=0 + wait "${FRONTEND_PID}" || status=$? + echo "平台前端已退出(状态码:${status}),正在停止后端。" >&2 + exit "${status}" + fi + sleep 1 +done