#!/usr/bin/env bash
# LunarFront — Sync local source to EC2 and redeploy
# Usage: bash deploy/sync-and-deploy.sh
set -euo pipefail

EC2_HOST="18.217.233.214"
EC2_USER="ubuntu"
SSH_KEY="$HOME/.ssh/lunarfront-dev.pem"
APP_DIR="/opt/lunarfront"

echo "==> Syncing source to ${EC2_USER}@${EC2_HOST}:${APP_DIR} ..."
rsync -az --delete \
  --exclude='.git' \
  --exclude='node_modules' \
  --exclude='packages/*/node_modules' \
  --exclude='packages/admin/dist' \
  --exclude='packages/backend/dist' \
  --exclude='*.env' \
  -e "ssh -i ${SSH_KEY} -o StrictHostKeyChecking=no" \
  /home/ryan/pos/ \
  "${EC2_USER}@${EC2_HOST}:${APP_DIR}/"

echo "==> Running deploy script on server..."
ssh -i "${SSH_KEY}" -o StrictHostKeyChecking=no "${EC2_USER}@${EC2_HOST}" \
  "sudo bash ${APP_DIR}/deploy/deploy.sh"
