|
| 1 | +param ( |
| 2 | + [Parameter(Position=0)] |
| 3 | + [string]$Command = "help" |
| 4 | +) |
| 5 | +Set-StrictMode -version latest; |
| 6 | +$ErrorActionPreference = 'Stop' |
| 7 | + |
| 8 | +function Exec { |
| 9 | + param([scriptblock]$CommandBlock) |
| 10 | + & $CommandBlock |
| 11 | + if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) { |
| 12 | + exit $LASTEXITCODE |
| 13 | + } |
| 14 | +} |
| 15 | +function Show-Help { |
| 16 | + $makefile = Join-Path $PSScriptRoot "Makefile" |
| 17 | + if (-not (Test-Path $makefile)) { |
| 18 | + Write-Host "Makefile not found." -ForegroundColor Yellow |
| 19 | + return |
| 20 | + } |
| 21 | + |
| 22 | + $commands = @() |
| 23 | + foreach ($line in Get-Content $makefile) { |
| 24 | + if ($line -match '^([a-zA-Z_-]+):.*?## (.*)$') { |
| 25 | + $commands += [PSCustomObject]@{ |
| 26 | + Name = $matches[1] |
| 27 | + Desc = $matches[2] |
| 28 | + } |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + foreach ($cmd in ($commands | Sort-Object Name)) { |
| 33 | + Write-Host ("{0,-20} {1}" -f $cmd.Name, $cmd.Desc) |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +function Start-Server { |
| 38 | + Write-Host "Starting server in background..." |
| 39 | + Start-Process -NoNewWindow uv -ArgumentList "run", "python", "server_main.py", "--port", "6400" |
| 40 | +} |
| 41 | + |
| 42 | +function Start-Client { |
| 43 | + Write-Host "Starting frontend server..." |
| 44 | + $env:VITE_API_BASE_URL="http://localhost:6400" |
| 45 | + Exec { npm run dev --prefix frontend } |
| 46 | +} |
| 47 | + |
| 48 | +function Stop-Servers { |
| 49 | + try { |
| 50 | + Push-Location (Join-Path $PSScriptRoot "frontend") |
| 51 | + try { |
| 52 | + Write-Host "Stopping backend server (port 6400)..." |
| 53 | + npx kill-port 6400 |
| 54 | + } catch { Write-Host " Port 6400: nothing to stop" -ForegroundColor DarkGray } |
| 55 | + try { |
| 56 | + Write-Host "Stopping frontend server (port 5173)..." |
| 57 | + npx kill-port 5173 |
| 58 | + } catch { Write-Host " Port 5173: nothing to stop" -ForegroundColor DarkGray } |
| 59 | + } finally { |
| 60 | + Pop-Location |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +function Sync-Graphs { |
| 65 | + Exec { uv run python tools/sync_vuegraphs.py } |
| 66 | +} |
| 67 | + |
| 68 | +function Validate-Yamls { |
| 69 | + Exec { uv run python tools/validate_all_yamls.py } |
| 70 | +} |
| 71 | + |
| 72 | +function Test-Backend { |
| 73 | + Exec { uv run pytest -v } |
| 74 | +} |
| 75 | + |
| 76 | +function Lint-Backend { |
| 77 | + Exec { uvx ruff check . } |
| 78 | +} |
| 79 | + |
| 80 | +switch ($Command) { |
| 81 | + "dev" { |
| 82 | + Start-Server |
| 83 | + Start-Client |
| 84 | + } |
| 85 | + "server" { |
| 86 | + Start-Server |
| 87 | + } |
| 88 | + "client" { |
| 89 | + Start-Client |
| 90 | + } |
| 91 | + "stop" { |
| 92 | + Stop-Servers |
| 93 | + } |
| 94 | + "sync" { |
| 95 | + Sync-Graphs |
| 96 | + } |
| 97 | + "validate-yamls" { |
| 98 | + Validate-Yamls |
| 99 | + } |
| 100 | + "check-backend" { |
| 101 | + Test-Backend |
| 102 | + Lint-Backend |
| 103 | + } |
| 104 | + "backend-tests" { |
| 105 | + Test-Backend |
| 106 | + } |
| 107 | + "backend-lint" { |
| 108 | + Lint-Backend |
| 109 | + } |
| 110 | + "help" { |
| 111 | + Show-Help |
| 112 | + } |
| 113 | + default { |
| 114 | + Write-Error "Unknown command: $Command" -ErrorAction Continue |
| 115 | + Show-Help |
| 116 | + exit 1 |
| 117 | + } |
| 118 | +} |
0 commit comments