#!/bin/bash

# Pre-build script to prevent ENOENT errors during Next.js build
# This creates the necessary directory structure and files that Next.js expects

echo "🔧 Setting up build environment..."

# Create the .next directory structure if it doesn't exist
mkdir -p .next/export
mkdir -p .next/server/pages

# Create empty 500.html file in export directory to prevent ENOENT error
touch .next/export/500.html

# Create empty 404.html file as well (just in case)
touch .next/export/404.html

echo "✅ Build environment prepared!"

# Now run the actual build
echo "🏗️  Starting Next.js build..."
next build

# Check if build was successful
if [ $? -eq 0 ]; then
    echo "🎉 Build completed successfully!"
else
    echo "❌ Build failed!"
    exit 1
fi
