-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeployAddon.ps1
More file actions
182 lines (153 loc) · 6.27 KB
/
DeployAddon.ps1
File metadata and controls
182 lines (153 loc) · 6.27 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# AscensionVanity Deployment Script
# Mirrors the addon folder to WoW AddOns directory for testing
#
# Usage:
# .\DeployAddon.ps1 -WoWPath "C:\Path\To\WoW\Interface\AddOns" # Specify your WoW path
# .\DeployAddon.ps1 -Watch # Deploy and watch for changes (auto-deploy on file change)
param(
[Parameter(Mandatory=$true)]
[string]$WoWPath,
[switch]$Watch,
[switch]$Force
)
# Configuration
$sourceFolder = Join-Path $PSScriptRoot "AscensionVanity"
$destinationFolder = Join-Path $WoWPath "AscensionVanity"
# Colors for output
$colorInfo = "Cyan"
$colorSuccess = "Green"
$colorWarning = "Yellow"
$colorError = "Red"
# Header
Write-Host "`nAscensionVanity Deployment Tool" -ForegroundColor $colorInfo
Write-Host "================================" -ForegroundColor $colorInfo
Write-Host "Source: $sourceFolder" -ForegroundColor Gray
Write-Host "Destination: $destinationFolder" -ForegroundColor Gray
Write-Host ""
# Validate source folder exists
if (-not (Test-Path $sourceFolder)) {
Write-Host "ERROR: Source folder not found: $sourceFolder" -ForegroundColor $colorError
exit 1
}
# Check if destination parent directory exists
$wowAddOnsPath = Split-Path $destinationFolder -Parent
if (-not (Test-Path $wowAddOnsPath)) {
Write-Host "ERROR: WoW AddOns directory not found: $wowAddOnsPath" -ForegroundColor $colorError
Write-Host "Please verify your WoW installation path." -ForegroundColor $colorWarning
exit 1
}
# Function to perform the deployment
function Deploy-Addon {
param([bool]$IsWatchMode = $false)
$timestamp = Get-Date -Format "HH:mm:ss"
if (-not $IsWatchMode) {
Write-Host "[$timestamp] Deploying addon..." -ForegroundColor $colorInfo
}
try {
# Create destination folder if it doesn't exist
if (-not (Test-Path $destinationFolder)) {
New-Item -ItemType Directory -Path $destinationFolder -Force | Out-Null
Write-Host "[$timestamp] Created destination folder" -ForegroundColor $colorSuccess
}
# Get all files to copy
$filesToCopy = Get-ChildItem -Path $sourceFolder -File -Recurse
$copiedCount = 0
$skippedCount = 0
foreach ($file in $filesToCopy) {
$relativePath = $file.FullName.Substring($sourceFolder.Length + 1)
$destPath = Join-Path $destinationFolder $relativePath
$destDir = Split-Path $destPath -Parent
# Create destination directory if needed
if (-not (Test-Path $destDir)) {
New-Item -ItemType Directory -Path $destDir -Force | Out-Null
}
# Copy if file doesn't exist or is newer or Force flag is set
$shouldCopy = $Force
if (-not $shouldCopy) {
if (-not (Test-Path $destPath)) {
$shouldCopy = $true
} else {
$sourceTime = $file.LastWriteTime
$destTime = (Get-Item $destPath).LastWriteTime
$shouldCopy = $sourceTime -gt $destTime
}
}
if ($shouldCopy) {
Copy-Item -Path $file.FullName -Destination $destPath -Force
$copiedCount++
if (-not $IsWatchMode) {
Write-Host " Copied: $relativePath" -ForegroundColor Gray
}
} else {
$skippedCount++
}
}
# Summary
if ($IsWatchMode) {
if ($copiedCount -gt 0) {
Write-Host "[$timestamp] Updated $copiedCount file(s)" -ForegroundColor $colorSuccess
}
} else {
Write-Host "`n[$timestamp] Deployment complete!" -ForegroundColor $colorSuccess
Write-Host " Files copied: $copiedCount" -ForegroundColor $colorSuccess
Write-Host " Files skipped (up-to-date): $skippedCount" -ForegroundColor Gray
Write-Host ""
}
return $true
} catch {
Write-Host "[$timestamp] ERROR: Deployment failed" -ForegroundColor $colorError
Write-Host $_.Exception.Message -ForegroundColor $colorError
return $false
}
}
# Initial deployment
$deploySuccess = Deploy-Addon -IsWatchMode $false
if (-not $deploySuccess) {
exit 1
}
# Watch mode
if ($Watch) {
Write-Host "Watch mode enabled - monitoring for changes..." -ForegroundColor $colorInfo
Write-Host "Press Ctrl+C to stop watching" -ForegroundColor $colorWarning
Write-Host ""
# Create file system watcher
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = $sourceFolder
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
# Track last deployment time to debounce multiple rapid changes
$lastDeployTime = Get-Date
$debounceSeconds = 2
# Define the action to take when a file changes
$action = {
$currentTime = Get-Date
$timeSinceLastDeploy = ($currentTime - $script:lastDeployTime).TotalSeconds
if ($timeSinceLastDeploy -gt $script:debounceSeconds) {
$script:lastDeployTime = $currentTime
Deploy-Addon -IsWatchMode $true
}
}
# Register event handlers
Register-ObjectEvent -InputObject $watcher -EventName Changed -Action $action | Out-Null
Register-ObjectEvent -InputObject $watcher -EventName Created -Action $action | Out-Null
Register-ObjectEvent -InputObject $watcher -EventName Deleted -Action $action | Out-Null
Register-ObjectEvent -InputObject $watcher -EventName Renamed -Action $action | Out-Null
# Keep script running
try {
while ($true) {
Start-Sleep -Seconds 1
}
} finally {
# Cleanup on exit
$watcher.Dispose()
Get-EventSubscriber | Unregister-Event
Write-Host "`nWatch mode stopped" -ForegroundColor $colorWarning
}
}
Write-Host "Deployment script finished" -ForegroundColor $colorInfo
Write-Host ""
Write-Host "To test in-game:" -ForegroundColor $colorInfo
Write-Host " 1. Launch World of Warcraft" -ForegroundColor Gray
Write-Host " 2. Type /reload to reload UI" -ForegroundColor Gray
Write-Host " 3. Type /av help to verify addon loaded" -ForegroundColor Gray
Write-Host ""