-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPackage.ps1
More file actions
143 lines (118 loc) · 5.76 KB
/
Package.ps1
File metadata and controls
143 lines (118 loc) · 5.76 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
# LanguageOne Multi-Version Package Script
# Create separate packages for each engine version for Fab approval
param(
[string]$OutputDir = "Packages\Release"
)
$PluginName = "LanguageOne"
$PluginSourceDir = "LanguageOne"
# Supported engine versions
$EngineVersions = @(
@{ Version = "5.1"; VersionString = "5.1.0" },
@{ Version = "5.2"; VersionString = "5.2.0" },
@{ Version = "5.3"; VersionString = "5.3.0" },
@{ Version = "5.4"; VersionString = "5.4.0" },
@{ Version = "5.5"; VersionString = "5.5.0" },
@{ Version = "5.6"; VersionString = "5.6.0" },
@{ Version = "5.7"; VersionString = "5.7.0" }
)
Write-Host "================================================" -ForegroundColor Cyan
Write-Host " LanguageOne Multi-Version Package Script" -ForegroundColor Cyan
Write-Host "================================================" -ForegroundColor Cyan
Write-Host ""
# Read original uplugin file
$UpluginPath = "$PluginSourceDir\$PluginName.uplugin"
$OriginalUplugin = Get-Content $UpluginPath -Raw -Encoding UTF8 | ConvertFrom-Json
$PluginVersion = $OriginalUplugin.VersionName
# Auto-update version in documentation files
Write-Host "Updating documentation version to v$PluginVersion..." -ForegroundColor Cyan
$DocFiles = @(
@{ Path = "Docs\翻译功能使用说明.md"; Pattern = "### v(\d+\.\d+) \(当前\)"; Replacement = "### v$PluginVersion (当前)" },
@{ Path = "Docs\TRANSLATION_GUIDE.md"; Pattern = "### v(\d+\.\d+) \(Current\)"; Replacement = "### v$PluginVersion (Current)" }
)
foreach ($Doc in $DocFiles) {
if (Test-Path $Doc.Path) {
$content = Get-Content $Doc.Path -Raw -Encoding UTF8
$newContent = $content -replace $Doc.Pattern, $Doc.Replacement
if ($content -ne $newContent) {
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
[System.IO.File]::WriteAllText($Doc.Path, $newContent, $utf8NoBom)
Write-Host " Updated: $($Doc.Path)" -ForegroundColor Green
}
}
}
Write-Host ""
# Create output directory
if (!(Test-Path $OutputDir)) {
New-Item -ItemType Directory -Path $OutputDir -Force | Out-Null
}
$ExcludeDirs = @("Binaries", "Intermediate", ".vs", "Saved", "DerivedDataCache")
$ExcludeFiles = @("*.pdb", "*.exp", "*.lib", "*.obj")
$TotalVersions = $EngineVersions.Count
for ($i = 0; $i -lt $TotalVersions; $i++) {
$EngineVer = $EngineVersions[$i]
$Version = $EngineVer.Version
$VersionString = $EngineVer.VersionString
# Calculate sort index (Newest version gets smallest number to appear first)
# UE 5.7 is last in array, we want it to be 01
# UE 5.1 is first in array, we want it to be 07
$SortIndex = $TotalVersions - $i
$SortPrefix = "{0:D2}" -f $SortIndex
Write-Host "================================================" -ForegroundColor Yellow
Write-Host " Packaging for UE $Version (Sort Index: $SortPrefix)" -ForegroundColor Yellow
Write-Host "================================================" -ForegroundColor Yellow
# Create temp directory
$TempDir = "$OutputDir\Temp_UE$Version"
if (Test-Path $TempDir) {
Remove-Item -Path $TempDir -Recurse -Force
}
New-Item -ItemType Directory -Path $TempDir -Force | Out-Null
# Copy plugin files
Write-Host " Copying plugin files..." -ForegroundColor Green
$ExcludeDirsParam = $ExcludeDirs | ForEach-Object { "/XD `"$_`"" }
$ExcludeFilesParam = $ExcludeFiles | ForEach-Object { "/XF `"$_`"" }
$RobocopyCmd = "robocopy `"$PluginSourceDir`" `"$TempDir\$PluginName`" /E /NFL /NDL /NJH /NJS $ExcludeDirsParam $ExcludeFilesParam"
Invoke-Expression $RobocopyCmd | Out-Null
if ($LASTEXITCODE -ge 8) {
Write-Host " File copy error!" -ForegroundColor Red
exit 1
}
# Modify uplugin file, add EngineVersion
Write-Host " Setting engine version: $VersionString" -ForegroundColor Green
$UpluginFilePath = "$TempDir\$PluginName\$PluginName.uplugin"
$upluginObj = Get-Content $UpluginFilePath -Raw -Encoding UTF8 | ConvertFrom-Json
# Add EngineVersion field
$upluginObj | Add-Member -NotePropertyName "EngineVersion" -NotePropertyValue $VersionString -Force
# Save modified JSON with formatting (UTF8 without BOM)
$jsonContent = $upluginObj | ConvertTo-Json -Depth 10
# Replace escaped characters back to original (e.g., \u0026 -> &)
$jsonContent = $jsonContent -replace '\\u0026', '&'
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
[System.IO.File]::WriteAllText($UpluginFilePath, $jsonContent, $utf8NoBom)
# Create ZIP package
# Naming format: 01_LanguageOne_UE5.7_v1.2.zip
$ZipName = "${SortPrefix}_${PluginName}_UE${Version}_v$($OriginalUplugin.VersionName).zip"
$ZipPath = "$OutputDir\$ZipName"
Write-Host " Creating ZIP: $ZipName" -ForegroundColor Green
if (Test-Path $ZipPath) {
Remove-Item $ZipPath -Force
}
Compress-Archive -Path "$TempDir\*" -DestinationPath $ZipPath -Force
# Clean up temp directory
Remove-Item -Path $TempDir -Recurse -Force
Write-Host " Done: $ZipName" -ForegroundColor Green
Write-Host ""
}
Write-Host "================================================" -ForegroundColor Green
Write-Host " All Packages Created Successfully!" -ForegroundColor Green
Write-Host "================================================" -ForegroundColor Green
Write-Host ""
Write-Host "Output Directory: $OutputDir" -ForegroundColor Cyan
Write-Host ""
Write-Host "Created Packages:" -ForegroundColor Yellow
Get-ChildItem -Path $OutputDir -Filter "*.zip" | ForEach-Object {
$sizeMB = [math]::Round($_.Length / 1MB, 2)
Write-Host " - $($_.Name) - $sizeMB MB" -ForegroundColor Gray
}
Write-Host ""
Write-Host "Upload each package to Fab for its corresponding engine version" -ForegroundColor Cyan
Write-Host ""