|
| 1 | +# Define color codes for PowerShell |
| 2 | +$Green = [System.ConsoleColor]::Green |
| 3 | +$DefaultColor = [System.ConsoleColor]::White |
| 4 | + |
| 5 | +# Store initial directory |
| 6 | +$InitialDir = Get-Location |
| 7 | + |
| 8 | +# Check if we're in scripts directory and navigate accordingly |
| 9 | +if ((Split-Path -Path (Get-Location) -Leaf) -eq "scripts") { |
| 10 | + Set-Location .. |
| 11 | +} |
| 12 | + |
| 13 | +Write-Host "Starting API (Flask) server..." |
| 14 | + |
| 15 | +# Create and activate virtual environment |
| 16 | +if (-not (Test-Path venv)) { |
| 17 | + python -m venv venv |
| 18 | +} |
| 19 | +if ($IsWindows) { |
| 20 | + & ./venv/Scripts/Activate.ps1 |
| 21 | +} else { |
| 22 | + & bash -c "source ./venv/bin/activate" |
| 23 | +} |
| 24 | + |
| 25 | +Set-Location server -ErrorAction Stop |
| 26 | +pip install -r requirements.txt |
| 27 | +Set-Location .. |
| 28 | +$env:FLASK_DEBUG = 1 |
| 29 | +$env:FLASK_PORT = 5100 |
| 30 | + |
| 31 | + |
| 32 | +# Start Python server |
| 33 | +$pythonProcess = Start-Process python ` |
| 34 | + -WorkingDirectory (Join-Path $PSScriptRoot "..\server") ` |
| 35 | + -ArgumentList "app.py" ` |
| 36 | + -PassThru ` |
| 37 | + -NoNewWindow |
| 38 | + |
| 39 | +Write-Host "Starting client (Astro)..." |
| 40 | +Set-Location client -ErrorAction Stop |
| 41 | +npm install |
| 42 | +cd .. |
| 43 | +if ($IsWindows) { |
| 44 | + $npcCmd = "npm.cmd" |
| 45 | +} else { |
| 46 | + $npcCmd = "npm" |
| 47 | +} |
| 48 | + |
| 49 | +$clientProcess = Start-Process "$npcCmd" ` |
| 50 | + -WorkingDirectory (Join-Path $PSScriptRoot "..\client") ` |
| 51 | + -ArgumentList "run", "dev", "--", "--no-clearScreen" ` |
| 52 | + -PassThru ` |
| 53 | + -NoNewWindow |
| 54 | + |
| 55 | +# Sleep for 5 seconds |
| 56 | +Start-Sleep -Seconds 5 |
| 57 | + |
| 58 | +# Display the server URLs |
| 59 | +Write-Host "`nServer (Flask) running at: http://localhost:5100" -ForegroundColor $Green |
| 60 | +Write-Host "Client (Astro) server running at: http://localhost:4321`n" -ForegroundColor $Green |
| 61 | +Write-Host "Ctrl+C to stop the servers" |
| 62 | + |
| 63 | +# Function to handle cleanup |
| 64 | +function Cleanup { |
| 65 | + Write-Host "Shutting down servers..." |
| 66 | + |
| 67 | + # Kill processes and their child processes |
| 68 | + if ($pythonProcess) { Stop-Process -Id $pythonProcess.Id -Force -ErrorAction SilentlyContinue } |
| 69 | + if ($clientProcess) { Stop-Process -Id $clientProcess.Id -Force -ErrorAction SilentlyContinue } |
| 70 | + |
| 71 | + # Deactivate virtual environment if it exists |
| 72 | + if (Test-Path Function:\deactivate) { |
| 73 | + deactivate |
| 74 | + } |
| 75 | + |
| 76 | + # Return to initial directory |
| 77 | + Set-Location $InitialDir |
| 78 | + exit |
| 79 | +} |
| 80 | + |
| 81 | +# Register cleanup for script termination |
| 82 | +$null = Register-EngineEvent -SourceIdentifier PowerShell.Exiting -Action { Cleanup } |
| 83 | + |
| 84 | +try { |
| 85 | + # Keep the script running until Ctrl+C |
| 86 | + Wait-Process -Id $pythonProcess.Id |
| 87 | +} finally { |
| 88 | + Cleanup |
| 89 | +} |
0 commit comments