#!/bin/bash
# Run this on your LAPTOP (not on the server), from the project root:
#   bash scripts/deploy-local.sh
#
# Builds the Next.js app, packages only what production needs
# (excludes .next/cache, node_modules, .git), and uploads it to the
# cPanel server. Does NOT touch backend/ — that's deployed separately.

set -e  # stop on first error

SERVER_USER="textspe1"
SERVER_HOST="5.9.147.93"
SERVER_PORT="1429"
REMOTE_PATH="~/tspeed_website/deploy.tar.gz"

echo "==> Building..."
npm run build

echo "==> Packaging (excluding .next/cache)..."
TARFILE="/tmp/deploy-$(date +%s).tar.gz"
tar -czf "$TARFILE" --exclude=".next/cache" .next public package.json package-lock.json next.config.mjs

echo "==> Uploading to server..."
scp -P "$SERVER_PORT" "$TARFILE" "$SERVER_USER@$SERVER_HOST:$REMOTE_PATH"

rm "$TARFILE"

echo ""
echo "==> Upload done. Now SSH in and run the server-side script:"
echo "    ssh -p $SERVER_PORT $SERVER_USER@$SERVER_HOST"
echo "    bash ~/tspeed_website/scripts/deploy-server.sh"
