#!/bin/bash
set -e
cd "$(cd "$(dirname "$0")/.." && pwd)"

SKIP_TESTS="${SKIP_TESTS:-0}"

echo "=== 清理旧构建产物 ==="
rm -rf frontend/dist
rm -rf backend/src/main/resources/static

if [ "$SKIP_TESTS" != "1" ]; then
    echo "=== 后端测试 ==="
    cd backend
    mvn -q test
    cd ..
fi

echo "=== 构建前端 ==="
cd frontend
[ ! -d node_modules ] && npm install
npm run build
cd ..

echo "=== 集成到后端 ==="
cp -r frontend/dist backend/src/main/resources/static

echo "=== 打包 JAR ==="
cd backend
mvn clean package -DskipTests -q

echo ""
echo "构建完成: backend/target/okr-performance-1.0.0.jar"
