#!/usr/bin/env bash
# build-frontend.sh — 构建 moziplus v2 前端
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
FRONTEND_DIR="$PROJECT_DIR/src/frontend"

echo "🔨 Building moziplus v2 frontend..."

cd "$FRONTEND_DIR"

# 安装依赖（首次或 lock 文件变化时）
if [ ! -d "node_modules" ] || [ "package-lock.json" -nt "node_modules" ]; then
  echo "📦 Installing dependencies..."
  npm install --frozen-lockfile 2>/dev/null || npm install
fi

# 构建
echo "🏗️  Building..."
npm run build

echo ""
echo "✅ Frontend built successfully"
echo "   Output: $FRONTEND_DIR/dist/"
