-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
99 lines (86 loc) · 3.2 KB
/
Copy pathinstall.ps1
File metadata and controls
99 lines (86 loc) · 3.2 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#Requires -Version 5.1
<#
.SYNOPSIS
Installs codebase-visualize for Claude Code or Codex at user or project scope.
.EXAMPLE
.\scripts\install.ps1 -Tool codex -Scope user
.\scripts\install.ps1 -Tool claude -Scope project -Force
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[ValidateSet('claude', 'codex')]
[string]$Tool,
[Parameter(Mandatory = $true)]
[ValidateSet('user', 'project')]
[string]$Scope,
[switch]$Force,
[string]$HomeRoot = $HOME,
[string]$ProjectRoot = (Get-Location).Path
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$sourceDir = (Resolve-Path (Join-Path $scriptDir '..\skills\codebase-visualize')).Path
$toolDir = if ($Tool -eq 'claude') { '.claude' } else { '.agents' }
$baseDir = if ($Scope -eq 'user') { $HomeRoot } else { $ProjectRoot }
$destDir = Join-Path $baseDir "$toolDir\skills\codebase-visualize"
$destParent = Split-Path -Parent $destDir
$stagingDir = "$destDir.install-$PID"
$backupDir = "$destDir.backup-$PID"
$required = @(
'SKILL.md',
'assets\renderer.css',
'lib\commands.mjs',
'scripts\visualize.mjs'
)
if (-not (Get-Command node -ErrorAction SilentlyContinue)) {
throw 'Node.js 18+ is required but node was not found on PATH.'
}
$nodeMajor = [int]((& node -p "process.versions.node.split('.')[0]").Trim())
if ($nodeMajor -lt 18) {
throw "Node.js 18+ is required; found major version $nodeMajor."
}
foreach ($path in $required) {
if (-not (Test-Path (Join-Path $sourceDir $path))) {
throw "Canonical skill package is missing required file: $path"
}
}
if (Test-Path $destDir) {
if (-not $Force) {
throw "Destination already exists: $destDir`nRe-run with -Force for a clean exact-sync replacement."
}
}
Write-Host "Source : $sourceDir"
Write-Host "Dest : $destDir"
Write-Host "Mode : $Tool / $Scope"
New-Item -ItemType Directory -Path $destParent -Force | Out-Null
Remove-Item -LiteralPath $stagingDir -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -LiteralPath $backupDir -Recurse -Force -ErrorAction SilentlyContinue
try {
Copy-Item -LiteralPath $sourceDir -Destination $stagingDir -Recurse
foreach ($path in $required) {
if (-not (Test-Path (Join-Path $stagingDir $path))) {
throw "Staged installation is missing required file: $path"
}
}
if (Test-Path $destDir) {
Move-Item -LiteralPath $destDir -Destination $backupDir
}
Move-Item -LiteralPath $stagingDir -Destination $destDir
Remove-Item -LiteralPath $backupDir -Recurse -Force -ErrorAction SilentlyContinue
} catch {
Remove-Item -LiteralPath $stagingDir -Recurse -Force -ErrorAction SilentlyContinue
if ((Test-Path $backupDir) -and -not (Test-Path $destDir)) {
Move-Item -LiteralPath $backupDir -Destination $destDir
}
throw
}
Write-Host ''
Write-Host 'Installation complete. No repository was visualized.'
Write-Host "Installed: $destDir"
Write-Host "Invoke explicitly, then run: node `"<skill-dir>\scripts\visualize.mjs`" --target `"<repo>`""
if ($Scope -eq 'project') {
Write-Host ''
Write-Host "Optional .gitignore pattern: $toolDir/skills/codebase-visualize/"
}