| 1 | # Publish Debug and copy to a fixed path without spaces (for Cursor MCP). |
| 2 | # Also builds samples/DebugTarget first (test target for DAP). |
| 3 | # Run from repo root: cd ...\cascade-ide ; .\scripts\deploy\publish-debug.ps1 |
| 4 | # Optional: -SkipDocGen (faster when IdeCommands XML-doc / MCP markdown codegen not changed) |
| 5 | # Optional: -Target "D:\cascade-ide-debug" |
| 6 | # Optional: -KillRunning (stop CascadeIDE from Target path if it locks publish output) |
| 7 | [CmdletBinding()] |
| 8 | param( |
| 9 | [string] $Target = "D:\cascade-ide-debug", |
| 10 | [switch] $SkipDocGen, |
| 11 | [switch] $KillRunning |
| 12 | ) |
| 13 | |
| 14 | $ErrorActionPreference = "Stop" |
| 15 | $repoRoot = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot "..\..")) |
| 16 | $csproj = Join-Path $repoRoot "CascadeIDE.csproj" |
| 17 | if (-not (Test-Path -LiteralPath $csproj)) { |
| 18 | Write-Error "CascadeIDE.csproj not found. Run from cascade-ide repo (resolved root=$repoRoot)." |
| 19 | exit 1 |
| 20 | } |
| 21 | |
| 22 | $debugTargetProj = Join-Path $repoRoot "samples\DebugTarget\DebugTarget.csproj" |
| 23 | $generic = Join-Path $repoRoot "scripts\deploy\publish-to-fixed-target.ps1" |
| 24 | |
| 25 | $intercomPublish = Join-Path $repoRoot "scripts\intercom\publish-intercom-service.ps1" |
| 26 | $intercomOut = Join-Path $repoRoot "artifacts\intercom-service" |
| 27 | |
| 28 | Push-Location $repoRoot |
| 29 | try { |
| 30 | if (Test-Path -LiteralPath $intercomPublish) { |
| 31 | & pwsh -NoProfile -ExecutionPolicy Bypass -File $intercomPublish -Configuration Debug -SelfContained -OutDir $intercomOut |
| 32 | if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } |
| 33 | } |
| 34 | |
| 35 | if (-not (Test-Path -LiteralPath $debugTargetProj)) { |
| 36 | Write-Error "DebugTarget project not found: $debugTargetProj" |
| 37 | exit 1 |
| 38 | } |
| 39 | & dotnet build $debugTargetProj -c Debug -v minimal |
| 40 | if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } |
| 41 | |
| 42 | if (-not (Test-Path -LiteralPath $generic)) { |
| 43 | Write-Error "Generic publish script not found: $generic" |
| 44 | exit 1 |
| 45 | } |
| 46 | |
| 47 | if ($SkipDocGen) { |
| 48 | & pwsh -NoProfile -ExecutionPolicy Bypass -File $generic ` |
| 49 | -Project $csproj ` |
| 50 | -Runtime "win-x64" ` |
| 51 | -Configuration "Debug" ` |
| 52 | -Target $Target ` |
| 53 | -SelfContained ` |
| 54 | -KillRunning:$KillRunning ` |
| 55 | -MsbuildProps "/p:GenerateIdeProtocolDocs=false" |
| 56 | } else { |
| 57 | & pwsh -NoProfile -ExecutionPolicy Bypass -File $generic ` |
| 58 | -Project $csproj ` |
| 59 | -Runtime "win-x64" ` |
| 60 | -Configuration "Debug" ` |
| 61 | -Target $Target ` |
| 62 | -SelfContained ` |
| 63 | -KillRunning:$KillRunning |
| 64 | } |
| 65 | if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } |
| 66 | |
| 67 | if (Test-Path -LiteralPath $intercomOut) { |
| 68 | $intercomTarget = Join-Path $Target "tools\intercom-service" |
| 69 | $intercomExeTarget = Join-Path $intercomTarget "IntercomService.exe" |
| 70 | foreach ($p in (Get-Process -Name "IntercomService" -ErrorAction SilentlyContinue)) { |
| 71 | try { |
| 72 | $path = $p.Path |
| 73 | if ($path -and [string]::Equals($path, $intercomExeTarget, [System.StringComparison]::OrdinalIgnoreCase)) { |
| 74 | Write-Host "Stopping IntercomService PID $($p.Id) (target copy is locked by running instance)" |
| 75 | Stop-Process -Id $p.Id -Force -ErrorAction Stop |
| 76 | } |
| 77 | } catch { |
| 78 | # Ignore path access issues; robocopy may still succeed if file is not locked. |
| 79 | } |
| 80 | } |
| 81 | New-Item -ItemType Directory -Path $intercomTarget -Force | Out-Null |
| 82 | robocopy $intercomOut $intercomTarget /E /MIR /NFL /NDL /NJH /NJS | Out-Null |
| 83 | if ($LASTEXITCODE -ge 8) { |
| 84 | Write-Error "robocopy intercom-service failed with exit code $LASTEXITCODE" |
| 85 | exit $LASTEXITCODE |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | $exe = Join-Path $Target "CascadeIDE.exe" |
| 90 | $exeJson = $exe.Replace('\', '\\') |
| 91 | Write-Host "Cursor MCP (debug): paste into mcp.json ->" |
| 92 | Write-Host @" |
| 93 | "cascade-ide-debug": { |
| 94 | "command": "$exeJson", |
| 95 | "args": ["--mcp-stdio"] |
| 96 | } |
| 97 | "@ |
| 98 | Write-Host "" |
| 99 | } finally { |
| 100 | Pop-Location |
| 101 | } |
| 102 | |