Repository navigation
Expand file tree
/
Copy pathopencode.ps1
More file actions
37 lines (37 loc) · 1.94 KB
/
Copy pathopencode.ps1
File metadata and controls
37 lines (37 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$ErrorActionPreference = 'Stop'
$node = (Get-Command node -CommandType Application -ErrorAction Stop | Select-Object -First 1).Source
$nodeVersion = & $node -p 'process.versions.node'
if ($LASTEXITCODE) { exit $LASTEXITCODE }
if ([int]($nodeVersion.Split('.')[0]) -lt 22) { throw 'Node.js 22+ with npm is required.' }
# Windows PowerShell 5.1 drops embedded quotes in native @args calls.
# Build an argv-equivalent command line, without cmd.exe or Invoke-Expression.
function ConvertTo-NativeArgument([string]$Value) {
$escaped = [regex]::Replace($Value, '(\\*)"', '$1$1\"')
$escaped = [regex]::Replace($escaped, '(\\+)$', '$1$1')
return '"' + $escaped + '"'
}
$work = $null
try {
$helper = $null
if ($PSScriptRoot -and (Test-Path -LiteralPath (Join-Path $PSScriptRoot 'opencode.mjs') -PathType Leaf)) {
$helper = Join-Path $PSScriptRoot 'opencode.mjs'
} else {
$work = Join-Path ([IO.Path]::GetTempPath()) ('lmm-opencode-' + [guid]::NewGuid())
New-Item -ItemType Directory -Path $work | Out-Null
$helper = Join-Path $work 'opencode.mjs'
Invoke-WebRequest -UseBasicParsing 'https://raw.githubusercontent.com/TokenNotIncluded/lmm-scripts/911e25385acaf7016e808bb0d5587301125061f5/opencode.mjs' -OutFile $helper
if ((Get-FileHash -LiteralPath $helper -Algorithm SHA256).Hash -ne '94f8966afd70c0218fb86898040ea25f1dbbdbc42a69e388adbebee8399ae31a') {
throw 'OpenCode setup script checksum mismatch; nothing was executed.'
}
}
$start = New-Object System.Diagnostics.ProcessStartInfo
$start.FileName = $node
$start.UseShellExecute = $false
$start.WorkingDirectory = $PWD.Path
$start.Arguments = ((@($helper) + @($args) | ForEach-Object { ConvertTo-NativeArgument $_ }) -join ' ')
$child = [Diagnostics.Process]::Start($start)
try { $child.WaitForExit(); $code = $child.ExitCode } finally { $child.Dispose() }
exit $code
} finally {
if ($work) { Remove-Item -LiteralPath $work -Recurse -Force -ErrorAction SilentlyContinue }
}