#!/usr/bin/env bash
# 本地构建前端并提示提交 dist（开发机执行，服务器不构建）
set -euo pipefail

ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "${ROOT}/frontend"

echo "[INFO] 安装依赖并构建前端…"
npm ci
npm run build

if [[ ! -f dist/index.html ]]; then
  echo "[ERROR] 构建失败：未生成 dist/index.html"
  exit 1
fi

echo ""
echo "构建完成。请提交并推送："
echo "  git add frontend/dist"
echo "  git commit -m \"build: update frontend dist\""
echo "  git push"
echo ""
echo "服务器更新："
echo "  bash /opt/secondary-school-grade-archive/deploy/update.sh"
