#!/bin/bash

# Deploy Frontend Only
# Use this when you've only made frontend changes

set -e

echo "🎨 Deploying Frontend Only..."

cd /home/luckychit/apps/chitfund

# Pull latest code
echo "📥 Pulling latest code..."
git stash 2>/dev/null || true
git pull origin prodnew

# Frontend
cd luckychit
echo "📦 Getting Flutter dependencies..."
flutter pub get

echo "🏗️  Building Flutter web app with cache-busting..."
# Add timestamp to force browser cache refresh
BUILD_NUMBER=$(date +%s)
flutter build web --release --web-renderer html --pwa-strategy=none --build-number=$BUILD_NUMBER
echo "📦 Build version: $BUILD_NUMBER (Service Worker: Disabled)"

echo "♻️  Restarting frontend..."
pm2 reload luckychit-frontend

echo "✅ Frontend deployed!"
pm2 status

