@echo off setlocal EnableExtensions EnableDelayedExpansion title MicroLearning - Development Launcher pushd "%~dp0" set "PHPRC=%~dp0backend" echo. echo MicroLearning Development Launcher echo ================================ echo. if not exist "backend\artisan" ( echo [ERROR] backend\artisan was not found. goto :fail ) if not exist "frontend\package.json" ( echo [ERROR] frontend\package.json was not found. goto :fail ) where php >nul 2>&1 || ( echo [ERROR] PHP is not available in PATH. goto :fail ) where composer >nul 2>&1 || ( echo [ERROR] Composer is not available in PATH. goto :fail ) where node >nul 2>&1 || ( echo [ERROR] Node.js is not available in PATH. goto :fail ) where npm >nul 2>&1 || ( echo [ERROR] npm is not available in PATH. goto :fail ) if /I "%~1"=="--check" goto :check_only if not exist "backend\.env" ( echo [SETUP] Creating backend\.env... copy /Y "backend\.env.example" "backend\.env" >nul || goto :fail ) if not exist "backend\vendor\autoload.php" ( echo [SETUP] Installing backend dependencies... pushd "backend" call composer install --no-interaction --prefer-dist || goto :fail_nested popd ) findstr /B /C:"APP_KEY=base64:" "backend\.env" >nul 2>&1 || ( echo [SETUP] Generating application key... pushd "backend" php artisan key:generate --force || goto :fail_nested popd ) if not exist "frontend\node_modules" ( echo [SETUP] Installing frontend dependencies... pushd "frontend" call npm install || goto :fail_nested popd ) echo [SETUP] Applying pending non-destructive migrations... pushd "backend" php artisan migrate --force || goto :fail_nested popd echo [START] Laravel API: http://127.0.0.1:8000 powershell -NoProfile -Command "if (Get-NetTCPConnection -LocalPort 8000 -State Listen -ErrorAction SilentlyContinue) { exit 0 } else { exit 1 }" >nul 2>&1 if errorlevel 1 ( start "MicroLearning API" /min cmd /k "cd /d ""%~dp0backend"" && php -d upload_max_filesize=2G -d post_max_size=2050M -d max_execution_time=0 artisan serve --host=127.0.0.1 --port=8000 --no-reload" ) else ( echo [OK] Port 8000 is already listening; reusing the current API process. ) echo [START] React app: http://127.0.0.1:5173 powershell -NoProfile -Command "if (Get-NetTCPConnection -LocalPort 5173 -State Listen -ErrorAction SilentlyContinue) { exit 0 } else { exit 1 }" >nul 2>&1 if errorlevel 1 ( start "MicroLearning Frontend" /min cmd /k "cd /d ""%~dp0frontend"" && npm run dev -- --host=127.0.0.1 --port=5173" ) else ( echo [OK] Port 5173 is already listening; reusing the current frontend process. ) echo [START] Background queue worker powershell -NoProfile -Command "$phpProcesses = Get-CimInstance Win32_Process -Filter 'Name = ''php.exe''' -ErrorAction SilentlyContinue; if ($phpProcesses.CommandLine -like '*artisan queue:work*') { exit 0 } else { exit 1 }" >nul 2>&1 if errorlevel 1 ( start "MicroLearning Queue" /min cmd /k "cd /d ""%~dp0backend"" && php artisan queue:work --tries=3 --timeout=600" ) else ( echo [OK] Queue worker is already running. ) echo [START] Background scheduler powershell -NoProfile -Command "$phpProcesses = Get-CimInstance Win32_Process -Filter 'Name = ''php.exe''' -ErrorAction SilentlyContinue; if ($phpProcesses.CommandLine -like '*artisan schedule:work*') { exit 0 } else { exit 1 }" >nul 2>&1 if errorlevel 1 ( start "MicroLearning Scheduler" /min cmd /k "cd /d ""%~dp0backend"" && php artisan schedule:work" ) else ( echo [OK] Scheduler is already running. ) echo [WAIT] Verifying API, frontend, and Vite proxy... set /a ready_attempts=0 :wait_for_services powershell -NoProfile -Command "try { $api = Invoke-WebRequest -UseBasicParsing -Uri 'http://127.0.0.1:8000/api/v1/health' -TimeoutSec 2; $front = Invoke-WebRequest -UseBasicParsing -Uri 'http://127.0.0.1:5173/' -TimeoutSec 2; $proxy = Invoke-WebRequest -UseBasicParsing -Uri 'http://127.0.0.1:5173/api/v1/health' -TimeoutSec 2; if ($api.StatusCode -eq 200 -and $front.StatusCode -eq 200 -and $proxy.StatusCode -eq 200) { exit 0 }; exit 1 } catch { exit 1 }" >nul 2>&1 if errorlevel 1 ( set /a ready_attempts+=1 if !ready_attempts! GEQ 30 ( echo [ERROR] Services did not become healthy within 30 seconds. echo Check the minimized API, Frontend, and Queue windows for details. goto :fail ) timeout /t 1 /nobreak >nul goto :wait_for_services ) echo [OK] API, frontend, and proxy health checks passed. start "" "http://127.0.0.1:5173" echo. echo [OK] Development services were launched in separate windows. echo Close those windows or press Ctrl+C in each one to stop them. popd exit /b 0 :check_only echo [OK] Project structure and required development tools are available. popd exit /b 0 :fail_nested popd :fail echo. echo [FAILED] The launcher could not complete startup. echo Review the error above, then run this file again. popd pause exit /b 1