$ErrorActionPreference = 'Stop' $projectRoot = Split-Path -Parent $PSScriptRoot $contractPath = Join-Path $projectRoot 'contracts\openapi.json' function Assert-ExitCode { param([string]$Step) if ($LASTEXITCODE -ne 0) { throw "$Step failed with exit code $LASTEXITCODE" } } Push-Location $projectRoot try { cargo run --quiet --manifest-path backend\Cargo.toml --bin export-openapi -- $contractPath Assert-ExitCode 'OpenAPI export' pnpm --dir frontend exec openapi-typescript ..\contracts\openapi.json -o src\api\generated.ts Assert-ExitCode 'TypeScript API generation' } finally { Pop-Location }