-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
82 lines (71 loc) · 3.37 KB
/
Copy pathinstall.ps1
File metadata and controls
82 lines (71 loc) · 3.37 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
[CmdletBinding()]
param(
[string]$UserRoot = $env:USERPROFILE,
[string]$DesktopRoot = [Environment]::GetFolderPath('Desktop'),
[string]$InstallRoot = (Join-Path $env:LOCALAPPDATA 'Programs\CCM'),
[string]$CommandRoot = (Join-Path $env:USERPROFILE 'bin'),
[switch]$ReplaceCodexSwitch,
[switch]$WhatIf
)
$ErrorActionPreference = 'Stop'
$sourceRoot = $PSScriptRoot
$commandPath = Join-Path $CommandRoot 'ccm.cmd'
$desktopPath = Join-Path $DesktopRoot 'CCM.cmd'
$oldSwitcherPath = Join-Path $DesktopRoot 'Codex Switch.cmd'
Write-Output "CCM install root: $InstallRoot"
Write-Output "CCM command: $commandPath"
Write-Output "CCM desktop entry: $desktopPath"
if ($ReplaceCodexSwitch) {
Write-Output "Old switcher replacement requested: $oldSwitcherPath"
}
if ($WhatIf) {
Write-Output 'WhatIf: no files or environment variables were changed.'
exit 0
}
try {
$nodeVersion = (& node.exe --version 2>$null).Trim()
} catch {
throw 'CCM requires Node.js 22 or newer. Install Node.js LTS, open a new terminal, then run this installer again.'
}
if ($nodeVersion -notmatch '^v(\d+)\.') {
throw "Unable to determine the installed Node.js version: $nodeVersion"
}
if ([int]$Matches[1] -lt 22) {
throw "CCM requires Node.js 22 or newer; found $nodeVersion. Upgrade Node.js, open a new terminal, then run this installer again."
}
$availableAgents = @('codex', 'claude', 'pi', 'grok') | Where-Object {
Get-Command $_ -ErrorAction SilentlyContinue
}
if (-not $availableAgents) {
Write-Warning 'No supported agent CLI was found yet. CCM will install, but install codex, claude, pi, or grok before managing that tool.'
} else {
Write-Output ("Detected agent CLIs: " + ($availableAgents -join ', '))
}
New-Item -ItemType Directory -Force -Path $InstallRoot, $CommandRoot, $DesktopRoot | Out-Null
Copy-Item -LiteralPath (Join-Path $sourceRoot 'ccm.js') -Destination (Join-Path $InstallRoot 'ccm.js') -Force
Copy-Item -LiteralPath (Join-Path $sourceRoot 'package.json') -Destination (Join-Path $InstallRoot 'package.json') -Force
Copy-Item -LiteralPath (Join-Path $sourceRoot 'lib') -Destination $InstallRoot -Recurse -Force
if (Test-Path -LiteralPath (Join-Path $sourceRoot 'README.md')) {
Copy-Item -LiteralPath (Join-Path $sourceRoot 'README.md') -Destination (Join-Path $InstallRoot 'README.md') -Force
}
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
$commandContent = "@echo off`r`nnode `"%LOCALAPPDATA%\Programs\CCM\ccm.js`" %*`r`n"
[IO.File]::WriteAllText($commandPath, $commandContent, $utf8NoBom)
$desktopContent = "@echo off`r`ncall `"%USERPROFILE%\bin\ccm.cmd`" %*`r`n"
[IO.File]::WriteAllText($desktopPath, $desktopContent, $utf8NoBom)
$userPath = [Environment]::GetEnvironmentVariable('Path', 'User')
$pathEntries = @($userPath -split ';' | Where-Object { $_ })
if ($pathEntries -notcontains $CommandRoot) {
$nextPath = (@($pathEntries) + $CommandRoot) -join ';'
[Environment]::SetEnvironmentVariable('Path', $nextPath, 'User')
Write-Output "Added to user PATH: $CommandRoot"
}
& node.exe (Join-Path $InstallRoot 'ccm.js') --doctor
if ($LASTEXITCODE -ne 0) {
throw "Installed CCM doctor failed with exit code $LASTEXITCODE"
}
if ($ReplaceCodexSwitch -and (Test-Path -LiteralPath $oldSwitcherPath)) {
Remove-Item -LiteralPath $oldSwitcherPath -Force
Write-Output "Removed old switcher: $oldSwitcherPath"
}
Write-Output 'CCM installation completed.'