publish-release.ps1 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. [CmdletBinding()]
  2. param(
  3. [string]$OutputDirectory = '',
  4. [switch]$IncludeUploads,
  5. [switch]$IncludeDatabase,
  6. [switch]$SkipBuild
  7. )
  8. $ErrorActionPreference = 'Stop'
  9. $ProjectRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
  10. if ([string]::IsNullOrWhiteSpace($OutputDirectory)) {
  11. $OutputDirectory = Join-Path $ProjectRoot 'release'
  12. }
  13. $OutputDirectory = [System.IO.Path]::GetFullPath($OutputDirectory)
  14. function Require-File([string]$Path, [string]$Message) {
  15. if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) {
  16. throw "$Message`nMissing: $Path"
  17. }
  18. }
  19. function Copy-OptionalFile([string]$Source, [string]$DestinationDirectory) {
  20. if (Test-Path -LiteralPath $Source -PathType Leaf) {
  21. Copy-Item -LiteralPath $Source -Destination $DestinationDirectory -Force
  22. return $true
  23. }
  24. return $false
  25. }
  26. function Validate-YamlWindowsPaths([string]$Path) {
  27. $lineNumber = 0
  28. foreach ($line in Get-Content -LiteralPath $Path) {
  29. $lineNumber++
  30. if ($line -match ':\s*"[^"]*\\[^"]*"') {
  31. throw "Invalid YAML path at $Path line $lineNumber. Use forward slashes (D:/data) or single quotes ('D:\data'), not a double-quoted backslash path."
  32. }
  33. }
  34. }
  35. if (-not $SkipBuild) {
  36. if ($null -eq (Get-Command wails -ErrorAction SilentlyContinue)) {
  37. throw 'Wails CLI was not found. Install Wails v2 before publishing.'
  38. }
  39. Write-Host 'Building Wails release...' -ForegroundColor Cyan
  40. Push-Location $ProjectRoot
  41. try {
  42. & wails build
  43. if ($LASTEXITCODE -ne 0) {
  44. throw "wails build failed with exit code $LASTEXITCODE"
  45. }
  46. } finally {
  47. Pop-Location
  48. }
  49. }
  50. $BinDirectory = Join-Path $ProjectRoot 'build\bin'
  51. $Executable = Join-Path $BinDirectory 'smart-parking.exe'
  52. $Config = Join-Path $ProjectRoot 'config.yaml'
  53. Require-File $Executable 'The Wails executable was not found. Run without -SkipBuild or build the project first.'
  54. Require-File $Config 'Production config.yaml was not found.'
  55. Validate-YamlWindowsPaths $Config
  56. $ReleaseName = 'smart-parking-' + (Get-Date -Format 'yyyyMMdd-HHmmss')
  57. $ReleaseDirectory = Join-Path $OutputDirectory $ReleaseName
  58. New-Item -ItemType Directory -Path $ReleaseDirectory -Force | Out-Null
  59. Copy-Item -LiteralPath $Executable -Destination $ReleaseDirectory -Force
  60. Copy-Item -LiteralPath $Config -Destination $ReleaseDirectory -Force
  61. $PrinterDLL = Join-Path $BinDirectory 'CsnPrinterLibs.dll'
  62. if (-not (Copy-OptionalFile $PrinterDLL $ReleaseDirectory)) {
  63. Write-Warning 'CsnPrinterLibs.dll was not found. Printing will be unavailable unless it is added before deployment.'
  64. }
  65. if ($IncludeUploads) {
  66. $Uploads = Join-Path $ProjectRoot 'uploads'
  67. if (Test-Path -LiteralPath $Uploads -PathType Container) {
  68. Copy-Item -LiteralPath $Uploads -Destination (Join-Path $ReleaseDirectory 'uploads') -Recurse -Force
  69. } else {
  70. Write-Warning 'uploads directory was not found; no local images were included.'
  71. }
  72. }
  73. if ($IncludeDatabase) {
  74. $AppData = [Environment]::GetFolderPath([Environment+SpecialFolder]::ApplicationData)
  75. $DatabaseDirectory = Join-Path $AppData 'smart-parking'
  76. $Database = Join-Path $DatabaseDirectory 'lc_garage.db'
  77. if (Test-Path -LiteralPath $Database -PathType Leaf) {
  78. $DatabasePackageDirectory = Join-Path $ReleaseDirectory 'data\AppData\smart-parking'
  79. New-Item -ItemType Directory -Path $DatabasePackageDirectory -Force | Out-Null
  80. Copy-Item -LiteralPath $Database -Destination $DatabasePackageDirectory -Force
  81. Copy-OptionalFile ($Database + '-wal') $DatabasePackageDirectory | Out-Null
  82. Copy-OptionalFile ($Database + '-shm') $DatabasePackageDirectory | Out-Null
  83. Write-Warning 'Database files were copied. Stop the source application before deployment to guarantee a consistent SQLite backup.'
  84. } else {
  85. Write-Warning "Database was not found: $Database"
  86. }
  87. }
  88. $Readme = @"
  89. Smart Parking deployment package
  90. Contents:
  91. - smart-parking.exe: Wails desktop application
  92. - config.yaml: production configuration. Review it before first start.
  93. - CsnPrinterLibs.dll: required when the CSN ticket printer is used.
  94. Prerequisites:
  95. - Windows x64
  96. - Microsoft Edge WebView2 Evergreen Runtime
  97. - Allow inbound TCP 8888 when edge devices or the central payment machine connect to this host.
  98. Before starting:
  99. 1. Set system.gate-simulator to false in config.yaml.
  100. 2. Set the production MQTT, camera, and ffmpeg configuration in config.yaml.
  101. 3. For Windows paths in YAML, use forward slashes (D:/SmartParking/data) or
  102. single quotes ('D:\SmartParking\data'). Do not use double-quoted paths with
  103. backslashes such as "D:\SmartParking\data"; YAML treats backslashes as escapes.
  104. 4. Start smart-parking.exe with this folder as its working directory.
  105. Database:
  106. - Default path: %APPDATA%\smart-parking\lc_garage.db for the Windows account that starts the application.
  107. - If a data folder is included, copy data\AppData\smart-parking\* to that exact path after the application is stopped.
  108. Local images:
  109. - Copy the included uploads folder next to smart-parking.exe when historical local images must be retained.
  110. "@
  111. Set-Content -LiteralPath (Join-Path $ReleaseDirectory 'DEPLOYMENT.txt') -Value $Readme -Encoding UTF8
  112. Write-Host ''
  113. Write-Host "Release package created: $ReleaseDirectory" -ForegroundColor Green
  114. Write-Host 'Deploy the complete directory to the production machine.' -ForegroundColor Green