Update NSIS installer and build script for improved file handling and icon management
All checks were successful
farmcontrol/farmcontrol-server/pipeline/head This commit looks good
All checks were successful
farmcontrol/farmcontrol-server/pipeline/head This commit looks good
- Changed the application source directory definition in the NSIS installer script to point to "app" for better clarity. - Updated the file inclusion pattern to ensure all files are correctly packaged in the installer. - Enhanced the build script to define a local installer name and manage the icon file more effectively, ensuring it is copied to the working directory if present. - Improved error handling to provide clearer messages regarding the installer creation process.
This commit is contained in:
parent
d572688370
commit
f04daa1998
@ -11,7 +11,7 @@
|
|||||||
!endif
|
!endif
|
||||||
|
|
||||||
!ifndef APP_SOURCE_DIR
|
!ifndef APP_SOURCE_DIR
|
||||||
!define APP_SOURCE_DIR "."
|
!define APP_SOURCE_DIR "app"
|
||||||
!endif
|
!endif
|
||||||
|
|
||||||
Name "Farm Control Server"
|
Name "Farm Control Server"
|
||||||
@ -48,7 +48,7 @@ FunctionEnd
|
|||||||
Section "Farm Control Server" SecMain
|
Section "Farm Control Server" SecMain
|
||||||
SectionIn RO
|
SectionIn RO
|
||||||
SetOutPath $INSTDIR
|
SetOutPath $INSTDIR
|
||||||
File /r "${APP_SOURCE_DIR}\*"
|
File /r "${APP_SOURCE_DIR}\*.*"
|
||||||
|
|
||||||
!insertmacro customInstall
|
!insertmacro customInstall
|
||||||
|
|
||||||
|
|||||||
@ -47,6 +47,7 @@ $rootDir = Split-Path -Parent $PSScriptRoot
|
|||||||
$nsiPath = Join-Path $rootDir "packaging/windows/farmcontrol-server.nsi"
|
$nsiPath = Join-Path $rootDir "packaging/windows/farmcontrol-server.nsi"
|
||||||
$installerInclude = Join-Path $rootDir "packaging/windows/installer.nsh"
|
$installerInclude = Join-Path $rootDir "packaging/windows/installer.nsh"
|
||||||
$workDir = Join-Path $env:TEMP "farmcontrol-server-nsis"
|
$workDir = Join-Path $env:TEMP "farmcontrol-server-nsis"
|
||||||
|
$localInstallerName = "farmcontrol-server-installer.exe"
|
||||||
|
|
||||||
if (Test-Path $workDir) {
|
if (Test-Path $workDir) {
|
||||||
Remove-Item $workDir -Recurse -Force
|
Remove-Item $workDir -Recurse -Force
|
||||||
@ -74,6 +75,11 @@ if (-not (Test-Path $requiredExe)) {
|
|||||||
Copy-Item -LiteralPath $nsiPath -Destination (Join-Path $workDir "farmcontrol-server.nsi")
|
Copy-Item -LiteralPath $nsiPath -Destination (Join-Path $workDir "farmcontrol-server.nsi")
|
||||||
Copy-Item -LiteralPath $installerInclude -Destination (Join-Path $workDir "installer.nsh")
|
Copy-Item -LiteralPath $installerInclude -Destination (Join-Path $workDir "installer.nsh")
|
||||||
|
|
||||||
|
$iconPath = Join-Path $rootDir "assets\icon.ico"
|
||||||
|
if (Test-Path $iconPath) {
|
||||||
|
Copy-Item -LiteralPath $iconPath -Destination (Join-Path $workDir "icon.ico") -Force
|
||||||
|
}
|
||||||
|
|
||||||
$makensis = Find-Makensis
|
$makensis = Find-Makensis
|
||||||
$outputExePath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($OutputExe)
|
$outputExePath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($OutputExe)
|
||||||
$outputDir = Split-Path $outputExePath -Parent
|
$outputDir = Split-Path $outputExePath -Parent
|
||||||
@ -81,17 +87,16 @@ if (-not (Test-Path $outputDir)) {
|
|||||||
New-Item -ItemType Directory -Path $outputDir | Out-Null
|
New-Item -ItemType Directory -Path $outputDir | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
$iconPath = Join-Path $rootDir "assets\icon.ico"
|
|
||||||
$makensisArgs = @(
|
$makensisArgs = @(
|
||||||
|
"/V3"
|
||||||
"/NOCD"
|
"/NOCD"
|
||||||
"/DOUTFILE=$outputExePath"
|
"/DOUTFILE=$localInstallerName"
|
||||||
"/DVERSION=$Version"
|
"/DVERSION=$Version"
|
||||||
"/DAPP_SOURCE_DIR=app"
|
"/DAPP_SOURCE_DIR=app"
|
||||||
)
|
)
|
||||||
|
|
||||||
if (Test-Path $iconPath) {
|
if (Test-Path (Join-Path $workDir "icon.ico")) {
|
||||||
$iconPathForNsis = $iconPath.Replace("\", "/")
|
$makensisArgs += "/DINSTALLER_ICON=icon.ico"
|
||||||
$makensisArgs += "/DINSTALLER_ICON=$iconPathForNsis"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$makensisArgs += (Join-Path $workDir "farmcontrol-server.nsi")
|
$makensisArgs += (Join-Path $workDir "farmcontrol-server.nsi")
|
||||||
@ -106,20 +111,18 @@ try {
|
|||||||
Pop-Location
|
Pop-Location
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not (Test-Path $outputExePath)) {
|
$localInstallerPath = Join-Path $workDir $localInstallerName
|
||||||
throw "NSIS installer was not created at $outputExePath"
|
if (-not (Test-Path $localInstallerPath)) {
|
||||||
|
throw "NSIS installer was not created at $localInstallerPath"
|
||||||
}
|
}
|
||||||
|
|
||||||
$installerBytes = (Get-Item -LiteralPath $outputExePath).Length
|
$installerBytes = (Get-Item -LiteralPath $localInstallerPath).Length
|
||||||
Write-Host "NSIS installer size: $([math]::Round($installerBytes / 1MB, 2)) MB"
|
Write-Host "NSIS installer size: $([math]::Round($installerBytes / 1MB, 2)) MB"
|
||||||
|
|
||||||
if ($installerBytes -lt $MinInstallerBytes) {
|
if ($installerBytes -lt $MinInstallerBytes) {
|
||||||
throw "NSIS installer is only $([math]::Round($installerBytes / 1KB, 1)) KiB at $outputExePath. The application files were not packaged. Check APP_SOURCE_DIR staging and NSIS logs."
|
throw "NSIS installer is only $([math]::Round($installerBytes / 1KB, 1)) KiB at $localInstallerPath. The application files were not packaged. Check NSIS logs above."
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Test-Path $iconPath) {
|
Move-Item -LiteralPath $localInstallerPath -Destination $outputExePath -Force
|
||||||
$embedIconScript = Join-Path $rootDir "scripts/embed-windows-exe-icon.mjs"
|
|
||||||
& bun $embedIconScript $outputExePath --icon $iconPath
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host "Created NSIS installer at $outputExePath"
|
Write-Host "Created NSIS installer at $outputExePath"
|
||||||
|
|||||||
@ -99,6 +99,17 @@ export async function embedWindowsExeIcon(exePath, options = {}) {
|
|||||||
throw new Error(`embed-windows-exe-icon: executable not found: ${exePath}`);
|
throw new Error(`embed-windows-exe-icon: executable not found: ${exePath}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const basename = path.basename(exePath).toLowerCase();
|
||||||
|
if (
|
||||||
|
basename.includes("farmcontrol-server-") &&
|
||||||
|
basename.endsWith(".exe") &&
|
||||||
|
!basename.endsWith("-setup.exe")
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
`embed-windows-exe-icon: refusing to patch NSIS installer ${basename}; use NSIS Icon/MUI_ICON instead`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const iconSourcePath = resolveWindowsIconSource(options.icon);
|
const iconSourcePath = resolveWindowsIconSource(options.icon);
|
||||||
const workDir =
|
const workDir =
|
||||||
options.workDir || path.join(rootDir, "build", ".windows-icon-work");
|
options.workDir || path.join(rootDir, "build", ".windows-icon-work");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user