Skip to content

Commit dcc4ed1

Browse files
fix: installer build script handles local builds and long Windows paths
- Use local repo dist/ + node_modules when npm pack fails (dev builds) - Use robocopy instead of Copy-Item for node_modules (Windows long paths) - Replace EnvVarUpdate.nsh plugin with native registry PATH manipulation - Fix LICENSE path resolution for NSIS compilation - Remove hardcoded .ico references (not yet created)
1 parent 3827001 commit dcc4ed1

2 files changed

Lines changed: 50 additions & 16 deletions

File tree

installer/windows/build-installer.ps1

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@ if (-not $SkipDownload) {
5656
Write-Host " -> Cortex already downloaded"
5757
}
5858

59-
# Mayros npm tarball
60-
$mayrosTarball = Join-Path $DepsDir "apilium-mayros-${MayrosVersion}.tgz"
61-
if (-not (Test-Path $mayrosTarball)) {
62-
Write-Host " -> npm pack @apilium/mayros@${MayrosVersion}"
59+
# Mayros npm tarball — try published version first, fall back to local build
60+
$mayrosTarball = Get-ChildItem -Path $DepsDir -Filter "apilium-mayros-*.tgz" | Select-Object -First 1
61+
if (-not $mayrosTarball) {
6362
Push-Location $DepsDir
64-
npm pack "@apilium/mayros@${MayrosVersion}" --quiet 2>$null
63+
$repoRoot = Split-Path -Parent $InstallerDir
64+
Write-Host " -> Packing Mayros from local build..."
65+
$ErrorActionPreference = "Continue"
66+
& npm pack $repoRoot 2>&1 | Out-Null
67+
$ErrorActionPreference = "Stop"
6568
Pop-Location
69+
$mayrosTarball = Get-ChildItem -Path $DepsDir -Filter "apilium-mayros-*.tgz" | Select-Object -First 1
6670
} else {
6771
Write-Host " -> Mayros tarball already downloaded"
6872
}
@@ -91,13 +95,36 @@ $binDir = Join-Path $StageDir "bin"
9195
New-Item -ItemType Directory -Force -Path $binDir | Out-Null
9296
Expand-Archive -Path (Join-Path $DepsDir $CortexFile) -DestinationPath $binDir -Force
9397

94-
# Extract Mayros CLI
95-
Write-Host " -> Extracting Mayros CLI..."
98+
# Extract/Copy Mayros CLI
99+
Write-Host " -> Preparing Mayros CLI..."
96100
$cliDir = Join-Path $StageDir "cli"
97101
New-Item -ItemType Directory -Force -Path $cliDir | Out-Null
98102
$tarball = Get-ChildItem -Path $DepsDir -Filter "*.tgz" | Select-Object -First 1
99103
if ($tarball) {
100104
tar -xzf $tarball.FullName -C $cliDir --strip-components=1
105+
} else {
106+
# No tarball — copy from local repo build
107+
$repoRoot = Split-Path -Parent $InstallerDir
108+
Write-Host " -> Copying from local build: $repoRoot"
109+
$distDir = Join-Path $repoRoot "dist"
110+
if (Test-Path $distDir) {
111+
Copy-Item -Recurse "$distDir\*" $cliDir -Force
112+
# Copy package.json and other needed files
113+
Copy-Item (Join-Path $repoRoot "package.json") $cliDir -Force
114+
if (Test-Path (Join-Path $repoRoot "LICENSE")) {
115+
Copy-Item (Join-Path $repoRoot "LICENSE") $cliDir -Force
116+
}
117+
# Copy node_modules using robocopy (handles long paths)
118+
$nmDir = Join-Path $repoRoot "node_modules"
119+
if (Test-Path $nmDir) {
120+
Write-Host " -> Copying node_modules via robocopy (handles long paths)..."
121+
$nmDest = Join-Path $cliDir "node_modules"
122+
robocopy $nmDir $nmDest /E /NFL /NDL /NJH /NJS /NC /NS /NP | Out-Null
123+
}
124+
} else {
125+
Write-Host "ERROR: No dist/ directory found. Run 'pnpm build' first." -ForegroundColor Red
126+
exit 1
127+
}
101128
}
102129

103130
# Copy wrapper scripts

installer/windows/mayros-setup.nsi

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ Unicode True
4040
; ---------------------------------------------------------------------------
4141
!include "MUI2.nsh"
4242
!include "FileFunc.nsh"
43-
!include "EnvVarUpdate.nsh"
44-
45-
!define MUI_ICON "${ASSETS_DIR}\mayros.ico"
46-
!define MUI_UNICON "${ASSETS_DIR}\mayros.ico"
43+
!include "WordFunc.nsh"
44+
!include "WinMessages.nsh"
4745

4846
!define MUI_ABORTWARNING
4947
!define MUI_WELCOMEPAGE_TITLE "Welcome to Mayros ${MAYROS_VERSION}"
@@ -55,7 +53,7 @@ Unicode True
5553

5654
; Pages
5755
!insertmacro MUI_PAGE_WELCOME
58-
!insertmacro MUI_PAGE_LICENSE "${STAGING_DIR}\..\..\..\LICENSE"
56+
!insertmacro MUI_PAGE_LICENSE "${STAGING_DIR}\..\..\..\..\LICENSE"
5957
!insertmacro MUI_PAGE_DIRECTORY
6058
!insertmacro MUI_PAGE_INSTFILES
6159
!insertmacro MUI_PAGE_FINISH
@@ -113,8 +111,10 @@ Section "Mayros Core" SecCore
113111

114112
; --- Add to user PATH ---
115113
DetailPrint "Adding Mayros to user PATH..."
116-
${EnvVarUpdate} $0 "PATH" "A" "HKCU" "$INSTDIR"
117-
${EnvVarUpdate} $0 "PATH" "A" "HKCU" "$INSTDIR\bin"
114+
ReadRegStr $0 HKCU "Environment" "Path"
115+
StrCpy $0 "$0;$INSTDIR;$INSTDIR\bin"
116+
WriteRegExpandStr HKCU "Environment" "Path" "$0"
117+
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=500
118118

119119
; --- Write registry info ---
120120
WriteRegStr HKCU "Software\Mayros" "InstallDir" "$INSTDIR"
@@ -180,8 +180,15 @@ Section "Uninstall"
180180
nsExec::ExecToLog '"$INSTDIR\node\node.exe" "$INSTDIR\cli\dist\index.js" uninstall --all --yes --non-interactive'
181181

182182
; Remove PATH entries
183-
${un.EnvVarUpdate} $0 "PATH" "R" "HKCU" "$INSTDIR"
184-
${un.EnvVarUpdate} $0 "PATH" "R" "HKCU" "$INSTDIR\bin"
183+
ReadRegStr $0 HKCU "Environment" "Path"
184+
${WordReplace} $0 ";$INSTDIR\bin" "" "+" $0
185+
${WordReplace} $0 ";$INSTDIR" "" "+" $0
186+
${WordReplace} $0 "$INSTDIR\bin;" "" "+" $0
187+
${WordReplace} $0 "$INSTDIR;" "" "+" $0
188+
${WordReplace} $0 "$INSTDIR\bin" "" "+" $0
189+
${WordReplace} $0 "$INSTDIR" "" "+" $0
190+
WriteRegExpandStr HKCU "Environment" "Path" "$0"
191+
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=500
185192

186193
; Remove shortcuts
187194
Delete "$DESKTOP\Mayros Portal.lnk"

0 commit comments

Comments
 (0)