Diffinery

codician/diffinerypublic

Open-source, agent-first GitHub and GitHub Actions alternative that runs on your own Cloudflare account: git hosting, pull requests, code review and drop-in GitHub Actions YAML on Workers, Durable Objects, R2 and Containers.

76 lines · 4.6 KBRaw History
1# Installs the Diffinery extension into the editors built on VS Code on this computer (Windows):
2#
3# powershell -c "irm https://diffinery.com/install-editor.ps1 | iex"
4#
5# Set $env:DIFFINERY_EDITORS = "cursor" (names: code, code-insiders, cursor, windsurf, codium) to choose.
6# Each editor's command-line tool is used from PATH, or from its usual install folder. The .vsix comes
7# from the server that served this script and is checked against the SHA-256 it publishes. The
8# extension updates itself afterwards. Served by Diffinery from apps/vscode/install/.
9$ErrorActionPreference = "Stop"
10$server = if ($env:DIFFINERY_URL) { $env:DIFFINERY_URL } else { "__DIFFINERY_URL__" }
11if ($server.StartsWith("__")) { $server = "https://diffinery.com" }
12$server = $server.TrimEnd("/")
13
14$known = @(
15 @{ Name = "code"; Label = "VS Code"; Paths = @("$env:LOCALAPPDATA\Programs\Microsoft VS Code\bin\code.cmd", "$env:ProgramFiles\Microsoft VS Code\bin\code.cmd") },
16 @{ Name = "code-insiders"; Label = "VS Code Insiders"; Paths = @("$env:LOCALAPPDATA\Programs\Microsoft VS Code Insiders\bin\code-insiders.cmd") },
17 @{ Name = "cursor"; Label = "Cursor"; Paths = @("$env:LOCALAPPDATA\Programs\cursor\resources\app\bin\cursor.cmd") },
18 @{ Name = "windsurf"; Label = "Windsurf"; Paths = @("$env:LOCALAPPDATA\Programs\Windsurf\bin\windsurf.cmd") },
19 @{ Name = "codium"; Label = "VSCodium"; Paths = @("$env:LOCALAPPDATA\Programs\VSCodium\bin\codium.cmd", "$env:ProgramFiles\VSCodium\bin\codium.cmd") }
20)
21$wanted = if ($env:DIFFINERY_EDITORS) { $env:DIFFINERY_EDITORS -split "[ ,]+" } else { @() }
22
23$meta = Invoke-RestMethod "$server/-/vscode/version.json"
24$tmp = Join-Path ([IO.Path]::GetTempPath()) ("diffinery-" + [Guid]::NewGuid())
25New-Item -ItemType Directory $tmp | Out-Null
26try {
27 $vsix = Join-Path $tmp "diffinery-$($meta.version).vsix"
28 Invoke-WebRequest "$server/-/vscode/diffinery-$($meta.version).vsix" -OutFile $vsix -UseBasicParsing
29 if ((Get-FileHash $vsix -Algorithm SHA256).Hash.ToLower() -ne $meta.sha256) { throw "The download didn't match the published SHA-256; nothing was installed." }
30 # A self-hosted Diffinery: leave its address where the extension looks when it starts (src/servers.ts), and it asks
31 # whether to use it. Editors' command-line tools can't change a setting, and their settings files are JSON with
32 # comments, so this doesn't edit them. Written before installing, since a running editor starts a new extension at once.
33 $conf = if ($env:XDG_CONFIG_HOME -and [IO.Path]::IsPathRooted($env:XDG_CONFIG_HOME)) { $env:XDG_CONFIG_HOME } else { Join-Path $(if ($env:HOME) { $env:HOME } else { $env:USERPROFILE }) ".config" }
34 $hintFile = Join-Path $conf "diffinery\editor-server"
35 $hint = $false
36 if ($server -ne "https://diffinery.com") {
37 try {
38 New-Item -ItemType Directory -Force (Split-Path $hintFile) | Out-Null
39 [IO.File]::WriteAllText($hintFile, "$server`n")
40 $hint = $true
41 } catch {}
42 } else {
43 Remove-Item -Force $hintFile -ErrorAction SilentlyContinue
44 }
45
46 $installed = 0
47 foreach ($e in $known) {
48 if ($wanted.Count -gt 0 -and $wanted -notcontains $e.Name) { continue }
49 $cli = (Get-Command "$($e.Name).cmd" -ErrorAction SilentlyContinue).Source
50 if (-not $cli) { $cli = $e.Paths | Where-Object { Test-Path $_ } | Select-Object -First 1 }
51 if (-not $cli) {
52 if ($wanted.Count -gt 0) { Write-Host "x $($e.Label): its command-line tool ($($e.Name)) wasn't found" }
53 continue
54 }
55 & $cli --install-extension $vsix --force | Out-Null
56 if ($LASTEXITCODE -eq 0) { Write-Host "v $($e.Label): Diffinery extension $($meta.version) installed"; $installed++ }
57 else { Write-Host "x $($e.Label): installing failed" }
58 }
59 if ($installed -eq 0) {
60 Write-Host "No editor took the extension. Install it from the editor instead: Extensions > ... > Install from VSIX..."
61 Write-Host "with $server/-/vscode/diffinery.vsix, or see $server/docs/repositories/clone-in-your-editor"
62 exit 1
63 }
64 Write-Host ""
65 if ($server -ne "https://diffinery.com") {
66 if ($hint) {
67 Write-Host "This Diffinery is $server. When the editor starts, the extension asks to use it: choose Use $($server -replace '^[a-z]+://', '')."
68 Write-Host "If it doesn't ask, run Diffinery: Use Another Server... from the Command Palette and enter $server."
69 } else {
70 Write-Host "This Diffinery is $server`: in the editor, run Diffinery: Use Another Server... from the Command Palette and enter it."
71 }
72 }
73 Write-Host "Next: in the editor, run Git: Clone and pick Clone from Diffinery. ($server/docs/repositories/clone-in-your-editor)"
74} finally {
75 Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue
76}