|
| 1 | +$ErrorActionPreference = "Stop" |
| 2 | + |
| 3 | +# Check git first |
| 4 | +if (!(Get-Command git -ErrorAction SilentlyContinue)) { |
| 5 | + Write-Error "Error: git is required but not installed." |
| 6 | + exit 1 |
| 7 | +} |
| 8 | + |
| 9 | +# Validate Node.js version |
| 10 | +if (!(Get-Command node -ErrorAction SilentlyContinue)) { |
| 11 | + Write-Error "Error: Node.js version 20 or higher is required." |
| 12 | + exit 1 |
| 13 | +} |
| 14 | + |
| 15 | +$nodeVersion = (node -v) -replace '^v','' |
| 16 | +$major = [int]($nodeVersion -split '\.')[0] |
| 17 | +if ($major -lt 20) { |
| 18 | + Write-Error "Error: Node.js version 20 or higher is required (Node.js 22.x is recommended)." |
| 19 | + exit 1 |
| 20 | +} |
| 21 | + |
| 22 | +# Detect available editors in the system |
| 23 | +$availableEditors = @() |
| 24 | +$editorCmds = @() |
| 25 | + |
| 26 | +function Check-Editor($Name, $Cmd) { |
| 27 | + if (Get-Command $Cmd -ErrorAction SilentlyContinue) { |
| 28 | + $script:availableEditors += $Name |
| 29 | + $script:editorCmds += $Cmd |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +Check-Editor "VS Code" "code" |
| 34 | +Check-Editor "VS Code Insiders" "code-insiders" |
| 35 | +Check-Editor "VSCodium" "codium" |
| 36 | +Check-Editor "Cursor" "cursor" |
| 37 | +Check-Editor "Antigravity" "agy-ide" |
| 38 | + |
| 39 | +if ($availableEditors.Count -eq 0) { |
| 40 | + Write-Host "Hint: If your editor is installed, you might need to add its command to your PATH." -ForegroundColor Yellow |
| 41 | + Write-Host "Open your editor, open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P), and run a command like: `"Shell Command: Install 'cursor' command in PATH`" (or 'agy-ide', etc.)." -ForegroundColor Yellow |
| 42 | + Write-Error "Error: No supported editors found in your PATH." |
| 43 | + exit 1 |
| 44 | +} |
| 45 | + |
| 46 | +Write-Host "Detected editors:" |
| 47 | +for ($i = 0; $i -lt $availableEditors.Count; $i++) { |
| 48 | + Write-Host "$($i + 1)) $($availableEditors[$i])" |
| 49 | +} |
| 50 | +Write-Host "a) All detected editors" |
| 51 | +Write-Host "q) Quit`n" |
| 52 | + |
| 53 | +$choice = Read-Host "Select editor(s) to install CWC to" |
| 54 | + |
| 55 | +if ($choice -eq 'q' -or $choice -eq 'Q') { |
| 56 | + Write-Host "Installation cancelled." |
| 57 | + exit 0 |
| 58 | +} elseif ($choice -ne 'a' -and $choice -ne 'A') { |
| 59 | + if ($choice -notmatch '^[0-9]+$' -or [int]$choice -lt 1 -or [int]$choice -gt $availableEditors.Count) { |
| 60 | + Write-Error "Invalid choice. Exiting." |
| 61 | + exit 1 |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +$tmpDir = Join-Path $env:TEMP ("CWC_Install_" + [Guid]::NewGuid().ToString().Substring(0,8)) |
| 66 | +New-Item -ItemType Directory -Path $tmpDir | Out-Null |
| 67 | +Write-Host "`nCloning repository into temporary directory..." |
| 68 | +git clone -q --depth 1 https://github.com/robertpiosik/CodeWebChat.git $tmpDir |
| 69 | + |
| 70 | +Push-Location $tmpDir |
| 71 | + |
| 72 | +Write-Host "Installing dependencies..." |
| 73 | +npx --yes pnpm install *>$null |
| 74 | + |
| 75 | +Write-Host "Building extension..." |
| 76 | +Set-Location apps/editor |
| 77 | +npx --yes pnpm run build *>$null |
| 78 | + |
| 79 | +$vsixFile = Get-ChildItem *.vsix | Select-Object -First 1 |
| 80 | + |
| 81 | +if (!$vsixFile) { |
| 82 | + Write-Error "Error: VSIX file was not generated." |
| 83 | + Pop-Location |
| 84 | + exit 1 |
| 85 | +} |
| 86 | + |
| 87 | +function Install-ToEditor($idx) { |
| 88 | + $editorName = $availableEditors[$idx] |
| 89 | + $editorCmd = $editorCmds[$idx] |
| 90 | + Write-Host "Installing to $editorName..." |
| 91 | + & $editorCmd --install-extension $vsixFile.FullName --force *>$null |
| 92 | +} |
| 93 | + |
| 94 | +if ($choice -eq 'a' -or $choice -eq 'A') { |
| 95 | + for ($i = 0; $i -lt $availableEditors.Count; $i++) { |
| 96 | + Install-ToEditor $i |
| 97 | + } |
| 98 | +} else { |
| 99 | + Install-ToEditor ([int]$choice - 1) |
| 100 | +} |
| 101 | + |
| 102 | +Write-Host "`nDone!" |
| 103 | + |
| 104 | +Pop-Location |
| 105 | +Remove-Item -Recurse -Force $tmpDir |
0 commit comments