-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathupdate-ai-game-developer.ps1
More file actions
198 lines (161 loc) · 5.78 KB
/
Copy pathupdate-ai-game-developer.ps1
File metadata and controls
198 lines (161 loc) · 5.78 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Updates com.ivanmurzak.unity.mcp package to the latest version
.DESCRIPTION
Fetches the latest version from GitHub releases and updates the dependency
version in package.json and manifest.json files.
.PARAMETER WhatIf
Preview changes without applying them
.EXAMPLE
.\update-ai-game-developer.ps1
.EXAMPLE
.\update-ai-game-developer.ps1 -WhatIf
#>
param(
[switch]$WhatIf
)
# Set location to repository root (parent of commands folder)
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$repoRoot = Split-Path -Parent $scriptDir
Push-Location $repoRoot
# Script configuration
$ErrorActionPreference = "Stop"
$PackageName = "com.ivanmurzak.unity.mcp"
$GitHubRepo = "IvanMurzak/Unity-MCP"
# Files to update
$TargetFiles = @(
"Unity-Package/Packages/com.ivanmurzak.unity.mcp.particlesystem/package.json",
"Unity-Package/Packages/manifest.json"
)
function Write-ColorText {
param([string]$Text, [string]$Color = "White")
Write-Host $Text -ForegroundColor $Color
}
function Get-LatestVersionFromGitHub {
param([string]$Repo)
try {
# Try to get the latest release first (most reliable)
$releaseUrl = "https://api.github.com/repos/$Repo/releases/latest"
$headers = @{ "User-Agent" = "PowerShell" }
try {
$release = Invoke-RestMethod -Uri $releaseUrl -Headers $headers -TimeoutSec 30
$tagName = $release.tag_name
Write-ColorText " Found latest release: $tagName" "Gray"
}
catch {
# Fallback to tags if no releases exist
Write-ColorText " No releases found, checking tags..." "Gray"
$tagsUrl = "https://api.github.com/repos/$Repo/tags"
$tags = Invoke-RestMethod -Uri $tagsUrl -Headers $headers -TimeoutSec 30
if ($tags.Count -eq 0) {
throw "No tags found in repository"
}
$tagName = $tags[0].name
Write-ColorText " Found latest tag: $tagName" "Gray"
}
# Remove 'v' prefix if present (e.g., v1.0.0 -> 1.0.0)
$version = $tagName -replace '^v', ''
return $version
}
catch {
throw "Failed to fetch version from GitHub: $($_.Exception.Message)"
}
}
function Get-CurrentVersion {
param([string]$FilePath, [string]$PackageName)
if (-not (Test-Path $FilePath)) {
return $null
}
$content = Get-Content $FilePath -Raw
$pattern = [regex]::Escape("`"$PackageName`"") + ':\s*"([^"]+)"'
if ($content -match $pattern) {
return $Matches[1]
}
return $null
}
function Update-PackageVersion {
param(
[string]$FilePath,
[string]$PackageName,
[string]$NewVersion,
[bool]$PreviewOnly = $false
)
if (-not (Test-Path $FilePath)) {
Write-ColorText " File not found: $FilePath" "Yellow"
return $null
}
$content = Get-Content $FilePath -Raw
$originalContent = $content
# Pattern to match the package dependency line
$pattern = '("' + [regex]::Escape($PackageName) + '":\s*")[^"]+"'
$replacement = '${1}' + $NewVersion + '"'
$newContent = $content -replace $pattern, $replacement
if ($originalContent -eq $newContent) {
Write-ColorText " No changes needed in: $FilePath" "Gray"
return $null
}
if (-not $PreviewOnly) {
Set-Content -Path $FilePath -Value $newContent -NoNewline
}
return @{
Path = $FilePath
OriginalContent = $originalContent
NewContent = $newContent
}
}
# Main execution
try {
Write-ColorText "🔄 Update AI Game Developer Package" "Cyan"
Write-ColorText "=====================================" "Cyan"
# Get current version from first file
$currentVersion = Get-CurrentVersion -FilePath $TargetFiles[0] -PackageName $PackageName
if ($currentVersion) {
Write-ColorText "📋 Current version: $currentVersion" "White"
}
else {
Write-ColorText "📋 Current version: not found" "Yellow"
}
# Fetch latest version from GitHub
Write-ColorText "`n🌐 Fetching latest version from GitHub..." "Cyan"
$latestVersion = Get-LatestVersionFromGitHub -Repo $GitHubRepo
Write-ColorText "📋 Latest version: $latestVersion" "White"
if ($currentVersion -eq $latestVersion) {
Write-ColorText "`n✅ Already up to date!" "Green"
Pop-Location
exit 0
}
Write-ColorText "`n🔍 Updating files..." "Cyan"
$updatedFiles = @()
foreach ($file in $TargetFiles) {
Write-ColorText " Processing: $file" "Gray"
$result = Update-PackageVersion -FilePath $file -PackageName $PackageName -NewVersion $latestVersion -PreviewOnly $WhatIf
if ($result) {
$updatedFiles += $result
Write-ColorText " ✓ Updated: $file" "Green"
}
}
if ($WhatIf) {
Write-ColorText "`n📋 Preview Summary:" "Cyan"
Write-ColorText " Files to update: $($updatedFiles.Count)" "White"
Write-ColorText " Version change: $currentVersion → $latestVersion" "White"
Write-ColorText "`n✅ Preview completed. Run without -WhatIf to apply changes." "Green"
}
else {
if ($updatedFiles.Count -gt 0) {
Write-ColorText "`n🎉 Update completed successfully!" "Green"
Write-ColorText " Updated $($updatedFiles.Count) file(s)" "White"
Write-ColorText " Version: $currentVersion → $latestVersion" "White"
Write-ColorText "`n💡 Remember to commit these changes to git" "Cyan"
}
else {
Write-ColorText "`n⚠️ No files were updated" "Yellow"
}
}
Pop-Location
}
catch {
Write-ColorText "`n❌ Script failed: $($_.Exception.Message)" "Red"
Pop-Location
exit 1
}