param( [string]$Version = "dev", [switch]$SkipVendorFiles ) $ErrorActionPreference = "Stop" $ProjectRoot = $PSScriptRoot $DistDir = Join-Path $ProjectRoot "dist" $VendorSource = Join-Path $ProjectRoot "..\card-read-service\package\DWCardReaderDLL" $VendorTarget = Join-Path $DistDir "package\DWCardReaderDLL" New-Item -ItemType Directory -Force -Path $DistDir | Out-Null Push-Location $ProjectRoot try { go test -buildvcs=false ./... if ($LASTEXITCODE -ne 0) { throw "Host tests failed with exit code $LASTEXITCODE" } $env:GOOS = "windows" $env:GOARCH = "386" $env:CGO_ENABLED = "0" go test -buildvcs=false ./... if ($LASTEXITCODE -ne 0) { throw "Windows 386 tests failed with exit code $LASTEXITCODE" } go build -buildvcs=false -trimpath -ldflags "-s -w -X main.version=$Version" -o (Join-Path $DistDir "readcard-go.exe") . if ($LASTEXITCODE -ne 0) { throw "Windows 386 build failed with exit code $LASTEXITCODE" } } finally { Pop-Location } Copy-Item -LiteralPath (Join-Path $ProjectRoot "config.json") -Destination (Join-Path $DistDir "config.json") -Force if (-not $SkipVendorFiles) { if (-not (Test-Path -LiteralPath (Join-Path $VendorSource "CardReaderDLL.dll"))) { throw "Vendor DLL directory not found: $VendorSource" } New-Item -ItemType Directory -Force -Path $VendorTarget | Out-Null Copy-Item -Path (Join-Path $VendorSource "*") -Destination $VendorTarget -Recurse -Force } Write-Host "Build completed: $DistDir"