#!/usr/bin/env bash
# deploy/install.sh
# Run this script after uploading the portal files to the server.
# It installs dependencies and builds the production bundle.
#
# Usage:
#   cd /home/dulcfokx/ytwatch-portal
#   bash deploy/install.sh

set -e

echo "==> Trading Bite Watch-Time Portal — Install & Build"
echo ""

# 1. Verify .env.local exists
if [ ! -f ".env.local" ]; then
  echo "ERROR: .env.local not found."
  echo "       Copy .env.example to .env.local and fill in all values before running this script."
  exit 1
fi

echo "==> Installing Node.js dependencies (production only)..."
npm ci --omit=dev

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

echo ""
echo "==> Build complete."
echo "    To start the portal, run:  pm2 start deploy/ecosystem.config.js"
echo "    To reload after update:    pm2 reload ytwatch"
