#!/bin/bash # WHOOSH Development Environment Startup Script # This script provides a fast development cycle with hot reload set -e echo "๐Ÿš€ Starting WHOOSH Development Environment" echo "=========================================" # Colors for output GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' # No Color # Check if we're in the right directory if [ ! -f "docker-compose.dev.yml" ]; then echo -e "${RED}โŒ Error: Please run this script from the whoosh project root directory${NC}" exit 1 fi # Function to check if backend is running check_backend() { local backend_url="https://whoosh.home.deepblack.cloud/api/health" local dev_url="http://localhost:8089/api/health" echo -e "${YELLOW}โณ Checking backend availability...${NC}" if curl -s -f "$backend_url" > /dev/null 2>&1; then echo -e "${GREEN}โœ… Production backend is available at $backend_url${NC}" return 0 elif curl -s -f "$dev_url" > /dev/null 2>&1; then echo -e "${GREEN}โœ… Development backend is available at $dev_url${NC}" return 0 else echo -e "${YELLOW}โš ๏ธ No backend detected. Will start development backend.${NC}" return 1 fi } # Function to start frontend only (with production backend) start_frontend_only() { echo -e "${GREEN}๐ŸŽฏ Starting frontend with hot reload (using production backend)${NC}" cd frontend # Install dependencies if needed if [ ! -d "node_modules" ]; then echo -e "${YELLOW}๐Ÿ“ฆ Installing frontend dependencies...${NC}" npm install fi # Create development .env cat > .env.development.local << EOF VITE_API_BASE_URL=https://whoosh.home.deepblack.cloud VITE_WS_BASE_URL=https://whoosh.home.deepblack.cloud VITE_ENABLE_DEBUG_MODE=true VITE_LOG_LEVEL=debug VITE_DEV_MODE=true EOF echo -e "${GREEN}๐Ÿ”ฅ Starting frontend development server with hot reload...${NC}" echo -e "${YELLOW}๐Ÿ’ก Frontend will be available at: http://localhost:3000${NC}" echo -e "${YELLOW}๐Ÿ’ก Backend API: https://whoosh.home.deepblack.cloud${NC}" echo -e "${YELLOW}๐Ÿ’ก Press Ctrl+C to stop${NC}" echo "" npm run dev } # Function to start full development stack start_full_stack() { echo -e "${GREEN}๐Ÿ”ง Starting full development stack with Docker Compose...${NC}" # Build and start development containers echo -e "${YELLOW}๐Ÿณ Building development containers...${NC}" docker-compose -f docker-compose.dev.yml build echo -e "${YELLOW}๐Ÿš€ Starting development containers...${NC}" docker-compose -f docker-compose.dev.yml up --remove-orphans } # Main menu show_menu() { echo "" echo "Choose development mode:" echo "1) Frontend only (hot reload, uses production backend) - FAST โšก" echo "2) Full stack (frontend + backend in Docker) - COMPLETE ๐Ÿ”ง" echo "3) Check system status ๐Ÿ“Š" echo "4) Clean development environment ๐Ÿงน" echo "5) Exit" echo "" } # Clean development environment clean_dev_env() { echo -e "${YELLOW}๐Ÿงน Cleaning development environment...${NC}" # Stop and remove dev containers docker-compose -f docker-compose.dev.yml down --remove-orphans || true # Remove dev images docker images --format "table {{.Repository}}\t{{.Tag}}" | grep "whoosh.*dev" | awk '{print $1":"$2}' | xargs -r docker rmi || true # Clean frontend if [ -d "frontend/node_modules" ]; then echo -e "${YELLOW}๐Ÿ“ฆ Cleaning frontend node_modules...${NC}" rm -rf frontend/node_modules fi # Clean local env files rm -f frontend/.env.development.local echo -e "${GREEN}โœ… Development environment cleaned${NC}" } # Check system status check_status() { echo -e "${YELLOW}๐Ÿ“Š System Status Check${NC}" echo "====================" # Check production backend if curl -s -f "https://whoosh.home.deepblack.cloud/api/health" > /dev/null 2>&1; then echo -e "${GREEN}โœ… Production backend: Online${NC}" else echo -e "${RED}โŒ Production backend: Offline${NC}" fi # Check development backend if curl -s -f "http://localhost:8089/api/health" > /dev/null 2>&1; then echo -e "${GREEN}โœ… Development backend: Online${NC}" else echo -e "${YELLOW}โš ๏ธ Development backend: Offline${NC}" fi # Check frontend if curl -s -f "http://localhost:3000" > /dev/null 2>&1; then echo -e "${GREEN}โœ… Development frontend: Online${NC}" else echo -e "${YELLOW}โš ๏ธ Development frontend: Offline${NC}" fi # Check Docker if docker ps > /dev/null 2>&1; then echo -e "${GREEN}โœ… Docker: Available${NC}" # Check dev containers DEV_CONTAINERS=$(docker-compose -f docker-compose.dev.yml ps --services --filter status=running 2>/dev/null | wc -l) if [ "$DEV_CONTAINERS" -gt 0 ]; then echo -e "${GREEN}โœ… Development containers: $DEV_CONTAINERS running${NC}" else echo -e "${YELLOW}โš ๏ธ Development containers: None running${NC}" fi else echo -e "${RED}โŒ Docker: Not available${NC}" fi # Check Node.js if command -v node > /dev/null 2>&1; then NODE_VERSION=$(node --version) echo -e "${GREEN}โœ… Node.js: $NODE_VERSION${NC}" else echo -e "${RED}โŒ Node.js: Not installed${NC}" fi } # Trap to clean up on exit cleanup() { echo -e "\n${YELLOW}๐Ÿ›‘ Shutting down development environment...${NC}" if [ -f docker-compose.dev.yml ]; then docker-compose -f docker-compose.dev.yml down > /dev/null 2>&1 || true fi } trap cleanup EXIT # Main script loop while true; do show_menu read -p "Enter your choice (1-5): " choice case $choice in 1) if check_backend; then start_frontend_only else echo -e "${RED}โŒ No backend available. Please choose option 2 for full stack or start the production backend.${NC}" sleep 2 fi ;; 2) start_full_stack ;; 3) check_status read -p "Press Enter to return to menu..." ;; 4) clean_dev_env read -p "Press Enter to return to menu..." ;; 5) echo -e "${GREEN}๐Ÿ‘‹ Goodbye!${NC}" exit 0 ;; *) echo -e "${RED}โŒ Invalid choice. Please enter 1-5.${NC}" sleep 1 ;; esac done