# Start Go API + SvelteKit web + worker from repo root (Windows PowerShell alternative to `npm run dev`). # Loads monorepo-root .env into this process so child go processes inherit it. $ErrorActionPreference = "Stop" $Root = Resolve-Path (Join-Path $PSScriptRoot "..") $envFile = Join-Path $Root ".env" if (Test-Path $envFile) { Get-Content $envFile | ForEach-Object { if ($_ -match '^\s*#' -or $_ -match '^\s*$') { return } $line = $_ if ($line -match '^\s*export\s+') { $line = $line -replace '^\s*export\s+', '' } $kv = $line -split '=', 2 if ($kv.Length -eq 2) { $name = $kv[0].Trim() if (-not [string]::IsNullOrWhiteSpace($name) -and -not (Test-Path "Env:$name")) { Set-Item -Path "Env:$name" -Value $kv[1].Trim().Trim('"').Trim("'") } } } } # Free unique ports then force them (keep in sync with scripts/dev-ports.mjs) & node (Join-Path $Root "scripts\free-dev-ports.mjs") if ($LASTEXITCODE -ne 0) { throw "free-dev-ports.mjs failed" } $env:DESCRYBE_DEV_PORTS_FREED = "1" $env:HTTP_ADDR = ":28471" $env:WEB_ORIGIN = "http://localhost:28472" $env:PUBLIC_API_URL = "http://localhost:28471" $api = Start-Process -PassThru -NoNewWindow -WorkingDirectory (Join-Path $Root "apps\api") -FilePath "go" -ArgumentList @("run", "./cmd/api") $worker = Start-Process -PassThru -NoNewWindow -WorkingDirectory (Join-Path $Root "apps\api") -FilePath "go" -ArgumentList @("run", "./cmd/worker") $web = Start-Process -PassThru -NoNewWindow -WorkingDirectory $Root -FilePath "npm" -ArgumentList @("run", "dev", "--workspace=web") function Stop-Children { foreach ($p in @($api, $worker, $web)) { if ($null -ne $p -and -not $p.HasExited) { Stop-Process -Id $p.Id -Force -ErrorAction SilentlyContinue } } } try { Wait-Process -Id @($api.Id, $worker.Id, $web.Id) } finally { Stop-Children }