2026-08-06 11:23:33 +08:00
|
|
|
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"
|
2026-08-12 13:40:06 +08:00
|
|
|
$ResourceFile = Join-Path $ProjectRoot "rsrc_windows_386.syso"
|
|
|
|
|
|
|
|
|
|
if (-not (Test-Path -LiteralPath $ResourceFile)) {
|
|
|
|
|
throw "Missing embedded Windows resource: $ResourceFile"
|
|
|
|
|
}
|
2026-08-06 11:23:33 +08:00
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-12 13:40:06 +08:00
|
|
|
go build -buildvcs=false -trimpath -ldflags "-s -w -H windowsgui -X main.version=$Version" -o (Join-Path $DistDir "readcard-go.exe") .
|
2026-08-06 11:23:33 +08:00
|
|
|
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"
|