Web-based Winamp controller for CarPC � Go backend, mobile-first UI
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.2KB

  1. #Requires -Version 5.1
  2. <#
  3. .SYNOPSIS
  4. Build roadamp.exe
  5. .PARAMETER OutDir
  6. Output directory. Defaults to the project root (where this script lives).
  7. .PARAMETER Version
  8. Version string embedded via -ldflags. Defaults to the current git tag/commit.
  9. .EXAMPLE
  10. .\build.ps1
  11. .\build.ps1 -OutDir C:\Deploy\roadamp
  12. #>
  13. param(
  14. [string]$OutDir = $PSScriptRoot,
  15. [string]$Version = ""
  16. )
  17. Set-StrictMode -Version Latest
  18. $ErrorActionPreference = 'Stop'
  19. Push-Location $PSScriptRoot
  20. try {
  21. # Resolve version from git if not supplied
  22. if (-not $Version) {
  23. $tag = git describe --tags --always --dirty 2>$null
  24. $Version = if ($tag) { $tag } else { "dev" }
  25. }
  26. $out = Join-Path $OutDir "roadamp.exe"
  27. Write-Host "Building roadamp $Version -> $out" -ForegroundColor Cyan
  28. # ── Patch sw.js with build version ────────────────────────────────────────
  29. # The service worker embeds a cache-bust token so installed PWA clients
  30. # pick up new assets after each release. We replace __BUILDVER__ in the
  31. # source file, run go build (which embeds it), then restore via git.
  32. $swPath = Join-Path $PSScriptRoot 'web\static\sw.js'
  33. $swOriginal = Get-Content $swPath -Raw
  34. try {
  35. $swPatched = $swOriginal -replace '__BUILDVER__', $Version
  36. [System.IO.File]::WriteAllText($swPath, $swPatched, [System.Text.Encoding]::UTF8)
  37. # ── Compile ───────────────────────────────────────────────────────────
  38. $env:GOOS = "windows"
  39. $env:GOARCH = "amd64"
  40. $env:CGO_ENABLED = "0"
  41. go build `
  42. -trimpath `
  43. -ldflags "-s -w -X main.Version=$Version" `
  44. -o $out `
  45. ./cmd/roadamp
  46. }
  47. finally {
  48. # Always restore sw.js so the template token is preserved in the repo.
  49. [System.IO.File]::WriteAllText($swPath, $swOriginal, [System.Text.Encoding]::UTF8)
  50. }
  51. $size = [math]::Round((Get-Item $out).Length / 1MB, 2)
  52. Write-Host "Done $out (${size} MB)" -ForegroundColor Green
  53. }
  54. finally {
  55. Pop-Location
  56. }