elder-yudao-pro/deploy/local/start-ui.sh

40 lines
1.4 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
set -euo pipefail
# shellcheck disable=SC1091
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common.sh"
ensure_runtime_dir
UI_DIR="$REPO_DIR/yudao-ui-admin-vue3"
VITE="$UI_DIR/node_modules/vite/bin/vite.js"
[[ -f "$VITE" ]] || { echo '前端依赖未安装,请在 yudao-ui-admin-vue3 执行 pnpm install --frozen-lockfile。' >&2; exit 1; }
PID_FILE="$RUNTIME_DIR/ui.pid"
if [[ -f "$PID_FILE" ]] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then
echo "前端已在运行,PID $(cat "$PID_FILE")。"; exit 1
fi
NODE="$(resolve_node)"
if (command -v lsof >/dev/null 2>&1 && lsof -nP -iTCP:"$ELDER_UI_PORT" -sTCP:LISTEN >/dev/null); then
echo "端口 $ELDER_UI_PORT 已被占用。" >&2; exit 1
fi
cat > "$UI_DIR/.env.desktop" <<EOF
NODE_ENV=development
VITE_DEV=true
VITE_PORT=$ELDER_UI_PORT
VITE_OPEN=false
VITE_BASE_URL=http://127.0.0.1:$ELDER_SERVER_PORT
VITE_UPLOAD_TYPE=server
VITE_UPLOAD_URL=http://127.0.0.1:$ELDER_SERVER_PORT/admin-api/infra/file/upload
VITE_API_BASEPATH=/dev-api
VITE_API_URL=/admin-api
VITE_BASE_PATH=/
VITE_APP_CAPTCHA_ENABLE=false
VITE_APP_DOCALERT_ENABLE=false
VITE_APP_BAIDU_CODE=
EOF
nohup "$NODE" "$VITE" --mode desktop --host 127.0.0.1 --port "$ELDER_UI_PORT" --strictPort \
>"$RUNTIME_DIR/ui-stdout.log" 2>"$RUNTIME_DIR/ui-stderr.log" &
echo $! > "$PID_FILE"
echo "前端已启动,PID $(cat "$PID_FILE"):http://127.0.0.1:$ELDER_UI_PORT"