-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
104 lines (84 loc) · 3.59 KB
/
Copy pathinstall.ps1
File metadata and controls
104 lines (84 loc) · 3.59 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
100
101
102
103
104
param(
[string]$TargetDir,
[switch]$SkipAutomations
)
$ErrorActionPreference = "Stop"
function Write-Step($message) {
Write-Host "[harness-installer] $message"
}
function Copy-WithBackup {
param(
[string]$SourcePath,
[string]$DestinationPath,
[string]$BackupRoot
)
if (Test-Path -LiteralPath $DestinationPath) {
$backupPath = Join-Path $BackupRoot ([IO.Path]::GetFileName($DestinationPath))
Write-Step "Backup existing item: $DestinationPath -> $backupPath"
Copy-Item -LiteralPath $DestinationPath -Destination $backupPath -Recurse -Force
Remove-Item -LiteralPath $DestinationPath -Recurse -Force
}
Write-Step "Install item: $DestinationPath"
Copy-Item -LiteralPath $SourcePath -Destination $DestinationPath -Recurse -Force
}
$PackageRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
if (-not $TargetDir) {
$TargetDir = Read-Host "Enter the absolute path of the target project directory"
}
if (-not $TargetDir) {
throw "No target directory provided. Installation cancelled."
}
$ResolvedTarget = [IO.Path]::GetFullPath($TargetDir)
if (-not (Test-Path -LiteralPath $ResolvedTarget)) {
Write-Step "Create target directory: $ResolvedTarget"
New-Item -ItemType Directory -Path $ResolvedTarget | Out-Null
}
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
$BackupRoot = Join-Path $ResolvedTarget ".harness-install-backup\$timestamp"
New-Item -ItemType Directory -Path $BackupRoot -Force | Out-Null
$itemsToInstall = @(
"AGENTS.md",
"PROJECT-WORKFLOW.md",
".project-memory",
"harness-regression",
"tools"
)
Write-Step "Install target: $ResolvedTarget"
Write-Step "Backup root: $BackupRoot"
foreach ($item in $itemsToInstall) {
$sourcePath = Join-Path $PackageRoot $item
if (-not (Test-Path -LiteralPath $sourcePath)) {
throw "Package is missing required item: $item"
}
$destinationPath = Join-Path $ResolvedTarget $item
Copy-WithBackup -SourcePath $sourcePath -DestinationPath $destinationPath -BackupRoot $BackupRoot
}
if (-not $SkipAutomations) {
$automationSource = Join-Path $PackageRoot "automations"
if (Test-Path -LiteralPath $automationSource) {
$codexAutomationRoot = Join-Path $env:USERPROFILE ".codex\automations"
New-Item -ItemType Directory -Path $codexAutomationRoot -Force | Out-Null
$automationMap = @{
"weekly-harness-maintenance.toml" = "weekly-harness-maintenance"
"monthly-harness-deep-audit.toml" = "monthly-harness-deep-audit"
}
foreach ($entry in $automationMap.GetEnumerator()) {
$sourceFile = Join-Path $automationSource $entry.Key
if (-not (Test-Path -LiteralPath $sourceFile)) {
continue
}
$targetFolder = Join-Path $codexAutomationRoot $entry.Value
$targetFile = Join-Path $targetFolder "automation.toml"
New-Item -ItemType Directory -Path $targetFolder -Force | Out-Null
if (Test-Path -LiteralPath $targetFile) {
$automationBackupRoot = Join-Path $BackupRoot "automations\$($entry.Value)"
New-Item -ItemType Directory -Path $automationBackupRoot -Force | Out-Null
Copy-Item -LiteralPath $targetFile -Destination (Join-Path $automationBackupRoot "automation.toml") -Force
}
Write-Step "Install automation config: $targetFile"
Copy-Item -LiteralPath $sourceFile -Destination $targetFile -Force
}
}
}
Write-Step "Installation complete."
Write-Step "If this is a Git project, review the diff before committing."