#!/usr/bin/env bash
set -euo pipefail

echo "Starting cPanel production deployment..."

if [ ! -f ".env" ]; then
  echo "Missing .env file. Create it from .env.production first."
  exit 1
fi

php -v
composer --version

echo "Installing PHP dependencies..."
composer install --no-dev --optimize-autoloader

echo "Installing Node dependencies and building assets..."
npm ci
npm run build

echo "Running Laravel production optimizations..."
php artisan migrate --force
php artisan optimize:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache
php artisan storage:link || true

echo "Deployment completed successfully."
