param( [string]$Version = "dev", [string]$OutDir = "dist-release", [switch]$SkipFrontend ) $ErrorActionPreference = "Stop" $Root = Resolve-Path (Join-Path $PSScriptRoot "..") $Out = Join-Path $Root $OutDir function Run-Step { param( [string]$WorkingDirectory, [string]$FilePath, [string[]]$Arguments ) Push-Location $WorkingDirectory try { & $FilePath @Arguments if ($LASTEXITCODE -ne 0) { throw "$FilePath $($Arguments -join ' ') failed with exit code $LASTEXITCODE" } } finally { Pop-Location } } if (-not $SkipFrontend) { foreach ($App in @("admin", "portal", "setup")) { $WebDir = Join-Path $Root "web\$App" if (-not (Test-Path (Join-Path $WebDir "node_modules"))) { Run-Step $WebDir "npm" @("install") } Run-Step $WebDir "npm" @("run", "build") } } New-Item -ItemType Directory -Force -Path $Out | Out-Null $Targets = @( @{ GOOS = "windows"; GOARCH = "amd64"; Name = "ymhut-unified-management-windows-amd64.exe" }, @{ GOOS = "linux"; GOARCH = "amd64"; Name = "ymhut-unified-management-linux-amd64" }, @{ GOOS = "linux"; GOARCH = "arm64"; Name = "ymhut-unified-management-linux-arm64" } ) foreach ($Target in $Targets) { $env:GOOS = $Target.GOOS $env:GOARCH = $Target.GOARCH $env:CGO_ENABLED = "0" $Output = Join-Path $Out $Target.Name Run-Step $Root "go" @("build", "-tags", "embed_web", "-buildvcs=false", "-trimpath", "-ldflags", "-s -w -X ymhut-box/server/unified-management/internal/config.Version=$Version", "-o", $Output, ".\cmd\unified-management") } Remove-Item Env:\GOOS -ErrorAction SilentlyContinue Remove-Item Env:\GOARCH -ErrorAction SilentlyContinue Remove-Item Env:\CGO_ENABLED -ErrorAction SilentlyContinue Write-Host "Built release binaries in $Out"