2026-04-21 20:59:52 +08:00
|
|
|
param(
|
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
|
|
|
[string]$OutputPath,
|
2026-04-23 19:04:39 +08:00
|
|
|
|
2026-04-21 20:59:52 +08:00
|
|
|
[Parameter(Mandatory=$true)]
|
|
|
|
|
[string]$Version,
|
2026-04-23 19:04:39 +08:00
|
|
|
|
2026-04-21 20:59:52 +08:00
|
|
|
[Parameter(Mandatory=$false)]
|
|
|
|
|
[string]$Codename = "Administrate"
|
|
|
|
|
)
|
|
|
|
|
|
2026-04-23 19:04:39 +08:00
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
|
|
|
|
|
function Normalize-ArgumentValue {
|
|
|
|
|
param(
|
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
|
|
|
[AllowEmptyString()]
|
|
|
|
|
[string]$Value
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
$trimmed = $Value.Trim()
|
|
|
|
|
if ($trimmed.Length -ge 2) {
|
|
|
|
|
$first = $trimmed[0]
|
|
|
|
|
$last = $trimmed[$trimmed.Length - 1]
|
|
|
|
|
if (($first -eq "'" -and $last -eq "'") -or ($first -eq '"' -and $last -eq '"')) {
|
|
|
|
|
return $trimmed.Substring(1, $trimmed.Length - 2).Trim()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $trimmed
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$OutputPath = Normalize-ArgumentValue -Value $OutputPath
|
|
|
|
|
$Version = Normalize-ArgumentValue -Value $Version
|
|
|
|
|
$Codename = Normalize-ArgumentValue -Value $Codename
|
|
|
|
|
|
|
|
|
|
if ([string]::IsNullOrWhiteSpace($OutputPath)) {
|
|
|
|
|
throw "OutputPath is required."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([string]::IsNullOrWhiteSpace($Version)) {
|
|
|
|
|
throw "Version is required."
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-21 20:59:52 +08:00
|
|
|
$versionInfo = @{
|
|
|
|
|
Version = $Version
|
|
|
|
|
Codename = $Codename
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$json = $versionInfo | ConvertTo-Json -Compress
|
|
|
|
|
$dir = Split-Path -Parent $OutputPath
|
|
|
|
|
|
2026-04-23 19:04:39 +08:00
|
|
|
if ([string]::IsNullOrWhiteSpace($dir)) {
|
|
|
|
|
throw "OutputPath must include a directory: $OutputPath"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(Test-Path -LiteralPath $dir)) {
|
2026-04-21 20:59:52 +08:00
|
|
|
New-Item -ItemType Directory -Path $dir -Force | Out-Null
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 19:04:39 +08:00
|
|
|
Set-Content -LiteralPath $OutputPath -Value $json -Encoding UTF8
|
2026-04-21 20:59:52 +08:00
|
|
|
Write-Host "Generated version file: $OutputPath" -ForegroundColor Green
|
|
|
|
|
Write-Host " Version: $Version" -ForegroundColor Gray
|
|
|
|
|
Write-Host " Codename: $Codename" -ForegroundColor Gray
|