Add standalone Go build alongside VSCode extension
Ports all five tools to a single 7.5 MB Windows exe with an embedded WebView2 window, file-based config, single-instance focus, and clean shutdown. Adds build.ps1 to build both targets from one command. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
132
build.ps1
Normal file
132
build.ps1
Normal file
@@ -0,0 +1,132 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Builds both the VSCode extension and the standalone Windows exe.
|
||||
|
||||
.DESCRIPTION
|
||||
- Extension: tsc compile -> out/extension.js
|
||||
- Standalone: go build -> standalone/hpl-toolbox.exe (single static binary)
|
||||
|
||||
Optionally packages the extension as a .vsix with -Package.
|
||||
|
||||
.EXAMPLE
|
||||
.\build.ps1
|
||||
.\build.ps1 -Package
|
||||
.\build.ps1 -Standalone # Skip the extension; build only the exe
|
||||
.\build.ps1 -Extension # Skip the standalone; build only the extension
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[switch]$Package,
|
||||
[switch]$Extension,
|
||||
[switch]$Standalone
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
Set-Location $repoRoot
|
||||
|
||||
# If neither was specified, build both.
|
||||
if (-not $Extension -and -not $Standalone) {
|
||||
$Extension = $true
|
||||
$Standalone = $true
|
||||
}
|
||||
|
||||
function Write-Step($msg) {
|
||||
Write-Host ""
|
||||
Write-Host "==> $msg" -ForegroundColor Cyan
|
||||
}
|
||||
|
||||
function Get-FileSize($path) {
|
||||
if (-not (Test-Path $path)) { return $null }
|
||||
$bytes = (Get-Item $path).Length
|
||||
if ($bytes -ge 1MB) { return "{0:N2} MB" -f ($bytes / 1MB) }
|
||||
if ($bytes -ge 1KB) { return "{0:N1} KB" -f ($bytes / 1KB) }
|
||||
return "$bytes B"
|
||||
}
|
||||
|
||||
# Ensure Go is on PATH (winget install doesn't update current session)
|
||||
if (-not (Get-Command go -ErrorAction SilentlyContinue)) {
|
||||
$goBin = "C:\Program Files\Go\bin"
|
||||
if (Test-Path "$goBin\go.exe") {
|
||||
$env:Path = "$goBin;$env:Path"
|
||||
} else {
|
||||
Write-Error "go not found on PATH. Install Go from https://go.dev/dl/"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
$summary = @()
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# VSCode extension
|
||||
# ----------------------------------------------------------------------
|
||||
if ($Extension) {
|
||||
Write-Step "Building VSCode extension (tsc)"
|
||||
if (-not (Test-Path "node_modules")) {
|
||||
Write-Host " node_modules missing - running npm install" -ForegroundColor Yellow
|
||||
npm install
|
||||
if ($LASTEXITCODE -ne 0) { Write-Error "npm install failed"; exit 1 }
|
||||
}
|
||||
npm run compile
|
||||
if ($LASTEXITCODE -ne 0) { Write-Error "tsc compile failed"; exit 1 }
|
||||
$extOut = Join-Path $repoRoot "out\extension.js"
|
||||
$summary += [pscustomobject]@{
|
||||
Artifact = "Extension (out/extension.js)"
|
||||
Size = Get-FileSize $extOut
|
||||
}
|
||||
|
||||
if ($Package) {
|
||||
Write-Step "Packaging .vsix"
|
||||
if (-not (Get-Command vsce -ErrorAction SilentlyContinue)) {
|
||||
Write-Host " vsce not found - installing via npx (one-time)" -ForegroundColor Yellow
|
||||
npx --yes @vscode/vsce package
|
||||
} else {
|
||||
vsce package
|
||||
}
|
||||
if ($LASTEXITCODE -ne 0) { Write-Error "vsce package failed"; exit 1 }
|
||||
$vsix = Get-ChildItem -Path $repoRoot -Filter "*.vsix" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
|
||||
if ($vsix) {
|
||||
$summary += [pscustomobject]@{
|
||||
Artifact = "Extension ($($vsix.Name))"
|
||||
Size = Get-FileSize $vsix.FullName
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# Standalone Windows exe
|
||||
# ----------------------------------------------------------------------
|
||||
if ($Standalone) {
|
||||
Write-Step "Building standalone exe (go build)"
|
||||
Push-Location (Join-Path $repoRoot "standalone")
|
||||
try {
|
||||
# If rsrc.syso is missing (e.g. fresh clone before icon embedding), regenerate.
|
||||
if (-not (Test-Path "rsrc.syso") -and (Test-Path "hpl.ico")) {
|
||||
if (Get-Command rsrc -ErrorAction SilentlyContinue) {
|
||||
Write-Host " Regenerating rsrc.syso" -ForegroundColor Yellow
|
||||
rsrc -ico hpl.ico -o rsrc.syso
|
||||
} else {
|
||||
Write-Host " rsrc tool missing - exe will build without embedded icon" -ForegroundColor Yellow
|
||||
Write-Host " (install with: go install github.com/akavel/rsrc@latest)" -ForegroundColor Yellow
|
||||
}
|
||||
}
|
||||
|
||||
go build -ldflags="-s -w -H windowsgui" -trimpath -o hpl-toolbox.exe .
|
||||
if ($LASTEXITCODE -ne 0) { Write-Error "go build failed"; exit 1 }
|
||||
|
||||
$exePath = Join-Path (Get-Location) "hpl-toolbox.exe"
|
||||
$summary += [pscustomobject]@{
|
||||
Artifact = "Standalone (standalone/hpl-toolbox.exe)"
|
||||
Size = Get-FileSize $exePath
|
||||
}
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# Summary
|
||||
# ----------------------------------------------------------------------
|
||||
Write-Step "Build complete"
|
||||
$summary | Format-Table -AutoSize | Out-Host
|
||||
Reference in New Issue
Block a user