#!/bin/bash
# Cleanup script to remove node_modules directories that can cause Docker conflicts

set -e

echo "🧹 Cleaning up node_modules directories to prevent Docker conflicts..."

# Remove node_modules in apps subdirectories
find ./apps -name "node_modules" -type d -exec rm -rf {} + 2>/dev/null || true

# Remove node_modules in core subdirectories  
find ./core -name "node_modules" -type d -exec rm -rf {} + 2>/dev/null || true

# Remove root node_modules
rm -rf ./node_modules 2>/dev/null || true

# Remove any .react-* or other npm temp directories in apps
find ./apps -name ".react-*" -type d -exec rm -rf {} + 2>/dev/null || true
find ./apps -name ".react-dom-*" -type d -exec rm -rf {} + 2>/dev/null || true

echo "✅ Cleanup complete!"
echo ""
echo "Note: If you want to clean up Docker volumes as well, run:"
echo "  docker-compose -f docker-compose.dev.yml down -v"
echo "  docker volume rm gridpilot_dev_node_modules gridpilot_dev_npm_cache"