-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
65 lines (56 loc) · 2.14 KB
/
Copy pathsetup.ps1
File metadata and controls
65 lines (56 loc) · 2.14 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# setup.ps1 - Windows bootstrap for opencode setup
# Ensures Node.js (with npm) exists, then runs setup-opencode.mjs.
# Works both locally (cloned repo) and piped:
# irm https://raw.githubusercontent.com/seiz888/opencode-setup/main/setup.ps1 | iex
$ErrorActionPreference = "Stop"
$RawBase = "https://raw.githubusercontent.com/seiz888/opencode-setup/main"
function Have($name) {
return [bool](Get-Command $name -ErrorAction SilentlyContinue)
}
function Refresh-Path {
$machine = [Environment]::GetEnvironmentVariable("Path", "Machine")
$user = [Environment]::GetEnvironmentVariable("Path", "User")
$env:Path = "$machine;$user"
}
Write-Host "=== opencode setup bootstrap (Windows) ==="
# resolve setup-opencode.mjs: local next to this script, else download to temp
$scriptDir = if ($PSScriptRoot) { $PSScriptRoot }
elseif ($MyInvocation.MyCommand.Path) { Split-Path -Parent $MyInvocation.MyCommand.Path }
else { $null }
$localMjs = if ($scriptDir) { Join-Path $scriptDir "setup-opencode.mjs" } else { $null }
if ($localMjs -and (Test-Path $localMjs)) {
$mjs = $localMjs
} else {
$mjs = Join-Path ([System.IO.Path]::GetTempPath()) "setup-opencode.mjs"
Write-Host "downloading setup-opencode.mjs ..."
Invoke-WebRequest -UseBasicParsing "$RawBase/setup-opencode.mjs" -OutFile $mjs
}
# 1. ensure node
if (Have "node") {
Write-Host "node found: $(node --version)"
} else {
Write-Host "node not found, installing..."
if (Have "winget") {
winget install --id OpenJS.NodeJS.LTS -e --accept-source-agreements --accept-package-agreements
Refresh-Path
}
if (-not (Have "node")) {
Write-Host "winget unavailable or failed; trying fnm..."
if (-not (Have "fnm") -and (Have "winget")) {
winget install --id Schniz.fnm -e --accept-source-agreements --accept-package-agreements
Refresh-Path
}
if (Have "fnm") {
fnm install --lts
fnm use --lts
}
}
Refresh-Path
}
if (-not (Have "node")) {
Write-Error "Could not install Node.js automatically. Install it from https://nodejs.org and re-run."
return
}
# 2. run the cross-platform installer
Write-Host "running setup-opencode.mjs ..."
node $mjs