#!/bin/bash

# ========================================
# 仅前端部署脚本
# 适用于只修改了前端代码的情况
# ========================================

set -e

GO_PROJECT_PATH="/www/wwwroot/nofx"
HTML_PROJECT_PATH="/www/wwwroot/149.88.81.229_9000"

echo "🎨 部署前端..."

cd "$GO_PROJECT_PATH"

# 拉取代码
echo "📥 拉取代码..."
git pull origin main

# 编译前端
cd web
echo "🔨 编译前端..."
npm install --production
npm run build

# 备份
echo "💾 备份旧文件..."
mkdir -p "$HTML_PROJECT_PATH/backup"
cp -r "$HTML_PROJECT_PATH"/*.html "$HTML_PROJECT_PATH/backup/" 2>/dev/null || true
cp -r "$HTML_PROJECT_PATH/assets" "$HTML_PROJECT_PATH/backup/" 2>/dev/null || true

# 部署
echo "📤 部署文件..."
cp -r dist/* "$HTML_PROJECT_PATH/"
chmod -R 755 "$HTML_PROJECT_PATH"

echo "✅ 前端部署完成！"
echo "访问: http://149.88.81.229:9000"
