<# .SYNOPSIS Generate bin/manifest.json - the update manifest for the Wails built-in updater (static-site scheme). .DESCRIPTION Reads the release package under bin, computes file size and version, and writes the upgrade manifest manifest.json. Upload both the package and manifest to the update site https://i.scwy.net/down/toolsbox/. The manifest must be named manifest.json; the artifact url is just the file name (same directory). .PARAMETER Exe The release package to generate the manifest for (absolute or relative path). Default: bin\TengTuToolbox-windows-amd64.exe, falling back to bin\TengTuToolbox.exe. .PARAMETER Version Manifest version. Default: read from AppVersion in settings.go, else the exe version info. .PARAMETER Notes Release notes (multi-line, use backtick n for newline). Default empty. .PARAMETER PublishedAt Publish time (ISO 8601 or parseable). Default: now. .PARAMETER OutFile Output manifest path. Default: bin\manifest.json. .EXAMPLE .\generate-manifest.ps1 .EXAMPLE .\generate-manifest.ps1 -Version 0.2.0 -Notes "`n- Feature A.`n- Fix B." #> [CmdletBinding()] param( [string]$Exe = "", [string]$Version = "", [string]$Notes = "", [string]$PublishedAt = "", [string]$OutFile = "" ) $ErrorActionPreference = 'Stop' $root = Split-Path -Parent $MyInvocation.MyCommand.Path $binDir = Join-Path $root 'bin' # 1) Resolve the release package if (-not $Exe) { $candidate = Join-Path $binDir 'TengTuToolbox-windows-amd64.exe' if (-not (Test-Path $candidate)) { $candidate = Join-Path $binDir 'TengTuToolbox.exe' } if (-not (Test-Path $candidate)) { throw 'Release package not found. Put the installer under bin or pass -Exe.' } $Exe = $candidate } $exePath = if ([System.IO.Path]::IsPathRooted($Exe)) { $Exe } else { Join-Path (Get-Location) $Exe } if (-not (Test-Path $exePath)) { throw "Release package not found: $exePath" } # 2) File name (artifact url = file name, uploaded alongside the manifest) $fileName = [System.IO.Path]::GetFileName($exePath) $fileSize = (Get-Item $exePath).Length # 3) Version: -Version first, then AppVersion in settings.go, then exe version info if (-not $Version) { $settingsPath = Join-Path $root 'settings.go' if (Test-Path $settingsPath) { $m = Select-String -Path $settingsPath -Pattern 'AppVersion\s*=\s*"([^"]+)"' if ($m) { $Version = $m.Matches[0].Groups[1].Value } } } if (-not $Version) { $ver = (Get-Item $exePath).VersionInfo $Version = if ($ver.ProductVersion) { $ver.ProductVersion } else { $ver.FileVersion } } if (-not $Version) { $Version = '0.0.0' } # 4) Publish time if (-not $PublishedAt) { $PublishedAt = (Get-Date).ToString('yyyy-MM-ddTHH:mm:sszzz') } else { try { $PublishedAt = ([datetime]$PublishedAt).ToString('yyyy-MM-ddTHH:mm:sszzz') } catch { } } # 5) (Manifest object no longer needed; JSON is built by hand below for stable indentation.) # 6) Write output if (-not $OutFile) { $OutFile = Join-Path $binDir 'manifest.json' } # Build the JSON by hand for stable 2-space indentation (ConvertTo-Json spacing varies by PS version). # Use ConvertTo-Json only to escape individual string values safely. function Esc([string]$s) { ($s | ConvertTo-Json -Compress) } $json = @( '{' ' "schemaVersion": 1,' ' "version": ' + (Esc $Version) + ',' ' "name": ' + (Esc 'TengTu Toolbox') + ',' ' "notes": ' + (Esc $Notes) + ',' ' "publishedAt": ' + (Esc $PublishedAt) + ',' ' "artifacts": [' ' {' ' "url": ' + (Esc $fileName) + ',' ' "filename": ' + (Esc $fileName) + ',' ' "platform": "windows",' ' "arch": "amd64",' ' "size": ' + $fileSize ' }' ' ]' '}' ) -join "`r`n" # Write without BOM (Go's json.Unmarshal rejects a UTF-8 BOM). PS5.1's Out-File -Encoding utf8 adds BOM. [System.IO.File]::WriteAllText($OutFile, $json, (New-Object System.Text.UTF8Encoding($false))) Write-Host "Generated update manifest: $OutFile" Write-Host " Package : $fileName ($fileSize bytes)" Write-Host " Version : $Version" Write-Host " PublishedAt: $PublishedAt" Write-Host "" Write-Host "Upload $fileName and manifest.json to https://i.scwy.net/down/toolsbox/"