#!/bin/bash

# Clean Build Script for Next.js
# This script removes all cache and build artifacts, then rebuilds the application

echo "🧹 Cleaning Next.js cache and build artifacts..."

# Remove .next directory
if [ -d ".next" ]; then
  echo "  ✓ Removing .next directory..."
  rm -rf .next
fi

# Remove node_modules cache
if [ -d "node_modules/.cache" ]; then
  echo "  ✓ Removing node_modules/.cache..."
  rm -rf node_modules/.cache
fi

echo ""
echo "🔨 Building application..."
npm run build

if [ $? -eq 0 ]; then
  echo ""
  echo "✅ Clean build completed successfully!"
else
  echo ""
  echo "❌ Build failed. Please check the errors above."
  exit 1
fi
