1
0

generate-manifest.ps1 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <#
  2. .SYNOPSIS
  3. Generate bin/manifest.json - the update manifest for the Wails built-in updater (static-site scheme).
  4. .DESCRIPTION
  5. Reads the release package under bin, computes file size and version, and writes the
  6. upgrade manifest manifest.json. Upload both the package and manifest to the update site
  7. https://i.scwy.net/down/toolsbox/. The manifest must be named manifest.json; the artifact
  8. url is just the file name (same directory).
  9. .PARAMETER Exe
  10. The release package to generate the manifest for (absolute or relative path).
  11. Default: bin\TengTuToolbox-windows-amd64.exe, falling back to bin\TengTuToolbox.exe.
  12. .PARAMETER Version
  13. Manifest version. Default: read from AppVersion in settings.go, else the exe version info.
  14. .PARAMETER Notes
  15. Release notes (multi-line, use backtick n for newline). Default empty.
  16. .PARAMETER PublishedAt
  17. Publish time (ISO 8601 or parseable). Default: now.
  18. .PARAMETER OutFile
  19. Output manifest path. Default: bin\manifest.json.
  20. .EXAMPLE
  21. .\generate-manifest.ps1
  22. .EXAMPLE
  23. .\generate-manifest.ps1 -Version 0.2.0 -Notes "`n- Feature A.`n- Fix B."
  24. #>
  25. [CmdletBinding()]
  26. param(
  27. [string]$Exe = "",
  28. [string]$Version = "",
  29. [string]$Notes = "",
  30. [string]$PublishedAt = "",
  31. [string]$OutFile = ""
  32. )
  33. $ErrorActionPreference = 'Stop'
  34. $root = Split-Path -Parent $MyInvocation.MyCommand.Path
  35. $binDir = Join-Path $root 'bin'
  36. # 1) Resolve the release package
  37. if (-not $Exe) {
  38. $candidate = Join-Path $binDir 'TengTuToolbox-windows-amd64.exe'
  39. if (-not (Test-Path $candidate)) {
  40. $candidate = Join-Path $binDir 'TengTuToolbox.exe'
  41. }
  42. if (-not (Test-Path $candidate)) {
  43. throw 'Release package not found. Put the installer under bin or pass -Exe.'
  44. }
  45. $Exe = $candidate
  46. }
  47. $exePath = if ([System.IO.Path]::IsPathRooted($Exe)) { $Exe } else { Join-Path (Get-Location) $Exe }
  48. if (-not (Test-Path $exePath)) {
  49. throw "Release package not found: $exePath"
  50. }
  51. # 2) File name (artifact url = file name, uploaded alongside the manifest)
  52. $fileName = [System.IO.Path]::GetFileName($exePath)
  53. $fileSize = (Get-Item $exePath).Length
  54. # 3) Version: -Version first, then AppVersion in settings.go, then exe version info
  55. if (-not $Version) {
  56. $settingsPath = Join-Path $root 'settings.go'
  57. if (Test-Path $settingsPath) {
  58. $m = Select-String -Path $settingsPath -Pattern 'AppVersion\s*=\s*"([^"]+)"'
  59. if ($m) { $Version = $m.Matches[0].Groups[1].Value }
  60. }
  61. }
  62. if (-not $Version) {
  63. $ver = (Get-Item $exePath).VersionInfo
  64. $Version = if ($ver.ProductVersion) { $ver.ProductVersion } else { $ver.FileVersion }
  65. }
  66. if (-not $Version) { $Version = '0.0.0' }
  67. # 4) Publish time
  68. if (-not $PublishedAt) {
  69. $PublishedAt = (Get-Date).ToString('yyyy-MM-ddTHH:mm:sszzz')
  70. } else {
  71. try { $PublishedAt = ([datetime]$PublishedAt).ToString('yyyy-MM-ddTHH:mm:sszzz') }
  72. catch { }
  73. }
  74. # 5) (Manifest object no longer needed; JSON is built by hand below for stable indentation.)
  75. # 6) Write output
  76. if (-not $OutFile) { $OutFile = Join-Path $binDir 'manifest.json' }
  77. # Build the JSON by hand for stable 2-space indentation (ConvertTo-Json spacing varies by PS version).
  78. # Use ConvertTo-Json only to escape individual string values safely.
  79. function Esc([string]$s) { ($s | ConvertTo-Json -Compress) }
  80. $json = @(
  81. '{'
  82. ' "schemaVersion": 1,'
  83. ' "version": ' + (Esc $Version) + ','
  84. ' "name": ' + (Esc 'TengTu Toolbox') + ','
  85. ' "notes": ' + (Esc $Notes) + ','
  86. ' "publishedAt": ' + (Esc $PublishedAt) + ','
  87. ' "artifacts": ['
  88. ' {'
  89. ' "url": ' + (Esc $fileName) + ','
  90. ' "filename": ' + (Esc $fileName) + ','
  91. ' "platform": "windows",'
  92. ' "arch": "amd64",'
  93. ' "size": ' + $fileSize
  94. ' }'
  95. ' ]'
  96. '}'
  97. ) -join "`r`n"
  98. # Write without BOM (Go's json.Unmarshal rejects a UTF-8 BOM). PS5.1's Out-File -Encoding utf8 adds BOM.
  99. [System.IO.File]::WriteAllText($OutFile, $json, (New-Object System.Text.UTF8Encoding($false)))
  100. Write-Host "Generated update manifest: $OutFile"
  101. Write-Host " Package : $fileName ($fileSize bytes)"
  102. Write-Host " Version : $Version"
  103. Write-Host " PublishedAt: $PublishedAt"
  104. Write-Host ""
  105. Write-Host "Upload $fileName and manifest.json to https://i.scwy.net/down/toolsbox/"