# WidgeTDC Development Startup Script # Robust startup med health checks param( [switch]$SkipDocker, [switch]$BackendOnly, [switch]$FrontendOnly ) $ErrorActionPreference = "Stop" Write-Host "" Write-Host "================================================" -ForegroundColor Cyan Write-Host " WidgeTDC Development Environment Startup" -ForegroundColor Cyan Write-Host "================================================" -ForegroundColor Cyan Write-Host "" # Function til at tjekke om en port er i brug function Test-Port { param([int]$Port) $connection = New-Object System.Net.Sockets.TcpClient try { $connection.Connect("localhost", $Port) $connection.Close() return $true } catch { return $false } } # Function til at vente på service function Wait-ForService { param( [string]$Name, [int]$Port, [int]$MaxAttempts = 30 ) Write-Host " Waiting for $Name on port $Port..." -NoNewline for ($i = 1; $i -le $MaxAttempts; $i++) { if (Test-Port -Port $Port) { Write-Host " OK" -ForegroundColor Green return $true } Start-Sleep -Seconds 1 Write-Host "." -NoNewline } Write-Host " TIMEOUT" -ForegroundColor Red return $false } # Step 1: Start Docker services if (-not $SkipDocker) { Write-Host "[1/4] Starting Docker infrastructure..." -ForegroundColor Yellow # Check if docker is running $dockerRunning = docker info 2>&1 | Select-String "Server Version" if (-not $dockerRunning) { Write-Host " ERROR: Docker is not running. Please start Docker Desktop." -ForegroundColor Red exit 1 } # Start services docker-compose up -d # Wait for services Write-Host "" Write-Host " Waiting for services to be healthy..." -ForegroundColor Gray $pgReady = Wait-ForService -Name "PostgreSQL" -Port 5432 -MaxAttempts 30 $redisReady = Wait-ForService -Name "Redis" -Port 6379 -MaxAttempts 20 $neo4jReady = Wait-ForService -Name "Neo4j" -Port 7687 -MaxAttempts 45 if (-not ($pgReady -and $redisReady)) { Write-Host "" Write-Host " WARNING: Some services failed to start. Backend may have limited functionality." -ForegroundColor Yellow } Write-Host "" } else { Write-Host "[1/4] Skipping Docker (--SkipDocker)" -ForegroundColor Gray } # Step 2: Install dependencies if needed Write-Host "[2/4] Checking dependencies..." -ForegroundColor Yellow if (-not (Test-Path "node_modules")) { Write-Host " Running npm install..." -ForegroundColor Gray npm install } Write-Host " Dependencies OK" -ForegroundColor Green Write-Host "" # Step 3: Build shared packages Write-Host "[3/4] Building shared packages..." -ForegroundColor Yellow npm run build:shared 2>&1 | Out-Null Write-Host " Shared packages built" -ForegroundColor Green Write-Host "" # Step 4: Start applications Write-Host "[4/4] Starting applications..." -ForegroundColor Yellow if ($BackendOnly) { Write-Host " Starting backend only..." -ForegroundColor Gray npm run dev:backend } elseif ($FrontendOnly) { Write-Host " Starting frontend only..." -ForegroundColor Gray npm run dev:frontend } else { Write-Host " Starting backend and frontend concurrently..." -ForegroundColor Gray Write-Host "" Write-Host "================================================" -ForegroundColor Green Write-Host " Backend: http://localhost:3001" -ForegroundColor White Write-Host " Frontend: http://localhost:5173" -ForegroundColor White Write-Host " Neo4j: http://localhost:7474" -ForegroundColor White Write-Host "================================================" -ForegroundColor Green Write-Host "" npm run dev }