#!/bin/bash
set -e

cd "$(dirname "$0")"
echo "=> 拉取最新代码..."
git pull

echo "=> 安装依赖..."
npm install

echo "=> 同步数据库..."
npx prisma generate
npx prisma db push

echo "=> 构建项目..."
npm run build

echo "=> 准备运行目录..."
cp -r .next/static .next/standalone/.next/static
cp -r public .next/standalone/public
mkdir -p uploads
ln -sf "$(pwd)/uploads" .next/standalone/uploads

echo "=> 重启应用..."
pm2 restart nanami-web || pm2 start ecosystem.config.js

echo "=> 部署完成!"
