#!/bin/bash
# 月子 SaaS 一键部署
# 用法：./deploy.sh [commit message]
set -e

SERVER="root@82.157.47.215"
COMMIT_MSG="${1:-deploy: update}"
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"

echo "▶ 构建前端..."
cd "$ROOT_DIR/frontend"
npm run build

echo "▶ 提交变更（含 dist）..."
cd "$ROOT_DIR"
git add -A
git diff --cached --quiet && echo "  无变更，跳过提交" || git commit -m "$COMMIT_MSG"

echo "▶ 推送到远程..."
git push origin main

echo "▶ 通知服务器更新..."
ssh "$SERVER" '/var/www/saas/deploy.sh'

echo ""
echo "✅ 部署完成！"
