Use recorded Node path during deploy

This commit is contained in:
武阳
2026-05-08 09:56:58 +08:00
parent de6bb12ae5
commit 18cfb60539
2 changed files with 52 additions and 9 deletions
+25 -1
View File
@@ -6,6 +6,7 @@ set -euo pipefail
# 如果本次改动包含依赖、systemd 模板或部署脚本变化,请使用 scripts/deploy-ubuntu.sh。
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ENV_FILE="${ROOT_DIR}/.env.deploy"
BACKEND_SERVICE="zk-data-agent-backend"
FRONTEND_SERVICE="zk-data-agent-frontend"
BRANCH="${1:-}"
@@ -19,6 +20,27 @@ fail() {
exit 1
}
resolve_npm_bin() {
if [[ -f "${ENV_FILE}" ]]; then
# shellcheck disable=SC1090
source "${ENV_FILE}"
fi
if [[ -n "${CLAW_NODE_BIN_DIR:-}" ]]; then
export PATH="${CLAW_NODE_BIN_DIR}:${PATH}"
fi
local npm_bin="${CLAW_NPM_BIN:-$(command -v npm || true)}"
if [[ -z "${npm_bin}" || ! -x "${npm_bin}" ]]; then
fail "缺少命令:npm。请先安装 Node.js 和 npm,或执行 bash scripts/deploy-ubuntu.sh 重新记录 Node.js 路径。"
fi
local node_bin_dir
node_bin_dir="$(dirname "${npm_bin}")"
export PATH="${node_bin_dir}:${PATH}"
if ! "${npm_bin}" --version >/dev/null 2>&1; then
fail "npm 不可用:${npm_bin}。请确认同目录下存在 node,或重新安装 Node.js/npm。"
fi
printf "%s\n" "${npm_bin}"
}
cd "${ROOT_DIR}"
[[ -d .git ]] || fail "${ROOT_DIR} 不是 git 仓库。"
@@ -38,7 +60,9 @@ git pull --ff-only origin "${BRANCH}"
log "构建前端"
cd "${ROOT_DIR}/frontend/app"
npm run build
npm_bin="$(resolve_npm_bin)"
export PATH="$(dirname "${npm_bin}"):${PATH}"
"${npm_bin}" run build
log "重启用户服务"
systemctl --user restart "${BACKEND_SERVICE}" "${FRONTEND_SERVICE}"