#!/bin/bash
# deploy.sh - Deploy kashilo.com to production server via rsync
#
# Usage:   ./deploy.sh [user@host] [remote-path]
# Example: ./deploy.sh admin@kashilo.com /home/admin/web/kashilo.com/public_html
#
# Prerequisites:
#   - SSH key authentication configured
#   - rsync installed locally and on server

set -e

# --- Configuration ---
REMOTE_USER_HOST="${1:-admin@kashilo.com}"
REMOTE_PATH="${2:-/home/admin/web/kashilo.com/public_html}"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
DIST_DIR="$SCRIPT_DIR/dist"

# --- Build (minify JS + CSS) ---
echo "Building..."
python3 "$SCRIPT_DIR/build.py"
echo ""

# --- Deploy from dist/ ---
echo "Deploying kashilo.com"
echo "  From: $DIST_DIR"
echo "  To:   $REMOTE_USER_HOST:$REMOTE_PATH"
echo ""

rsync -avz --delete \
    "$DIST_DIR/" \
    "$REMOTE_USER_HOST:$REMOTE_PATH/"

echo ""
echo "Deploy complete."
