install.ps1 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # CodeGraph standalone installer for Windows (PowerShell).
  2. #
  3. # Downloads a self-contained bundle (a vendored Node runtime + the app) from
  4. # GitHub Releases. No Node.js, no build tools required.
  5. #
  6. # irm https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.ps1 | iex
  7. #
  8. # Upgrade with `codegraph upgrade` (or just re-run this). To uninstall: remove
  9. # $env:LOCALAPPDATA\codegraph and drop its \current\bin entry from your user PATH.
  10. #
  11. # Environment:
  12. # CODEGRAPH_VERSION release tag to install (default: latest)
  13. # CODEGRAPH_INSTALL_DIR install location (default: %LOCALAPPDATA%\codegraph)
  14. $ErrorActionPreference = 'Stop'
  15. $repo = 'colbymchenry/codegraph'
  16. $installDir = if ($env:CODEGRAPH_INSTALL_DIR) { $env:CODEGRAPH_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA 'codegraph' }
  17. # 1. Detect architecture -> target matching the release archives.
  18. $arch = if ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture -eq 'Arm64') { 'arm64' } else { 'x64' }
  19. $target = "win32-$arch"
  20. # 2. Resolve the version (latest release unless pinned).
  21. $version = $env:CODEGRAPH_VERSION
  22. if (-not $version) {
  23. $version = (Invoke-RestMethod "https://api.github.com/repos/$repo/releases/latest").tag_name
  24. }
  25. if (-not $version) { throw "codegraph: could not resolve latest version; set CODEGRAPH_VERSION." }
  26. # 3. Download + extract the bundle into a stable 'current' dir (overwritten on upgrade).
  27. $url = "https://github.com/$repo/releases/download/$version/codegraph-$target.zip"
  28. Write-Host "Installing CodeGraph $version ($target)..."
  29. $tmp = Join-Path $env:TEMP ("cg-" + [guid]::NewGuid().ToString())
  30. New-Item -ItemType Directory -Force -Path $tmp | Out-Null
  31. $zip = Join-Path $tmp 'cg.zip'
  32. Invoke-WebRequest -Uri $url -OutFile $zip
  33. $dest = Join-Path $installDir 'current'
  34. if (Test-Path $dest) { Remove-Item -Recurse -Force $dest }
  35. New-Item -ItemType Directory -Force -Path $dest | Out-Null
  36. Expand-Archive -Path $zip -DestinationPath $dest -Force
  37. # Archives contain a top-level codegraph-<target>\ dir; flatten it.
  38. $inner = Join-Path $dest "codegraph-$target"
  39. if (Test-Path $inner) {
  40. Get-ChildItem -Force $inner | Move-Item -Destination $dest -Force
  41. Remove-Item -Recurse -Force $inner
  42. }
  43. Remove-Item -Recurse -Force $tmp
  44. # 4. Put the launcher dir on the user's PATH.
  45. $binDir = Join-Path $dest 'bin'
  46. $userPath = [Environment]::GetEnvironmentVariable('Path', 'User')
  47. if (($userPath -split ';') -notcontains $binDir) {
  48. [Environment]::SetEnvironmentVariable('Path', "$binDir;$userPath", 'User')
  49. Write-Host "Added $binDir to your PATH (restart your terminal to pick it up)."
  50. }
  51. Write-Host "Installed to $dest"
  52. Write-Host "Run: codegraph --help"