#!/bin/bash
set -e

echo "===== 1. 拉取最新代码 ====="
git fetch --all
git reset --hard origin/master
echo "代码更新完成"

echo ""
echo "===== 2. 安装依赖 ====="
pnpm i
echo "依赖安装完成"

echo ""
echo "===== 3. 重启服务 ====="
if pm2 describe cytx_api > /dev/null 2>&1; then
  pm2 restart cytx_api
  echo "pm2 已重启 cytx_api"
else
  pm2 start pm2.json
  echo "pm2 已启动 cytx_api"
fi

echo ""
pm2 status
echo "===== 部署完成 ====="
