Skip to content

Commit 70aa49c

Browse files
committed
fix(review-feedback-1256): address latest review comments
1 parent b1b0368 commit 70aa49c

2 files changed

Lines changed: 87 additions & 9 deletions

File tree

scripts/build-desktop-macos.sh

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,49 @@ if [[ ! -d "${ROOT_DIR}/dist/backend/stock_analysis" ]]; then
1616
fi
1717

1818
pushd "${ROOT_DIR}/apps/dsa-desktop" >/dev/null
19-
if [[ ! -d node_modules ]]; then
19+
20+
package_lock_hash() {
21+
if command -v shasum >/dev/null 2>&1; then
22+
shasum -a 256 package-lock.json | awk '{print $1}'
23+
elif command -v sha256sum >/dev/null 2>&1; then
24+
sha256sum package-lock.json | awk '{print $1}'
25+
else
26+
echo "No SHA-256 checksum tool found. Install shasum or sha256sum." >&2
27+
exit 1
28+
fi
29+
}
30+
31+
install_desktop_dependencies() {
32+
local reason="$1"
33+
34+
echo "Installing desktop dependencies (${reason})..."
2035
npm install
21-
fi
36+
mkdir -p node_modules
37+
package_lock_hash > node_modules/.dsa-package-lock.sha256
38+
}
39+
40+
ensure_desktop_dependencies() {
41+
local marker="node_modules/.dsa-package-lock.sha256"
42+
local reason=""
43+
44+
if [[ ! -d node_modules ]]; then
45+
reason="node_modules missing"
46+
elif [[ ! -f "${marker}" ]]; then
47+
reason="package-lock marker missing"
48+
elif [[ "$(tr -d '[:space:]' < "${marker}")" != "$(package_lock_hash)" ]]; then
49+
reason="package-lock.json changed"
50+
elif [[ ! -d node_modules/electron-updater ]]; then
51+
reason="electron-updater missing"
52+
fi
53+
54+
if [[ -n "${reason}" ]]; then
55+
install_desktop_dependencies "${reason}"
56+
else
57+
echo "Desktop dependencies are up to date."
58+
fi
59+
}
60+
61+
ensure_desktop_dependencies
2262

2363
if compgen -G "dist/mac*" >/dev/null; then
2464
echo "Cleaning dist/mac*..."

scripts/build-desktop.ps1

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,53 @@ if (!(Test-Path $backendArtifact)) {
2929
throw "Backend artifact not found: $backendArtifact. Run scripts\build-backend.ps1 first."
3030
}
3131

32-
Write-Host 'Building Electron desktop app...'
33-
Push-Location (Join-Path $repoRoot 'apps\dsa-desktop')
34-
if (!(Test-Path 'node_modules')) {
32+
function Get-PackageLockHash {
33+
return (Get-FileHash -Path 'package-lock.json' -Algorithm SHA256).Hash
34+
}
35+
36+
function Install-DesktopDependencies {
37+
param(
38+
[string]$Reason,
39+
[switch]$Clean
40+
)
41+
42+
Write-Host "Installing desktop dependencies ($Reason)..."
43+
if ($Clean -and (Test-Path 'node_modules')) {
44+
Remove-Item -Recurse -Force 'node_modules'
45+
}
3546
npm install
47+
if ($LASTEXITCODE -ne 0) {
48+
throw 'Desktop dependency installation failed.'
49+
}
50+
New-Item -ItemType Directory -Force -Path 'node_modules' | Out-Null
51+
Set-Content -Path 'node_modules\.dsa-package-lock.sha256' -Value (Get-PackageLockHash) -Encoding ascii
52+
}
53+
54+
function Ensure-DesktopDependencies {
55+
$lockHashMarker = 'node_modules\.dsa-package-lock.sha256'
56+
$installReason = $null
57+
58+
if (!(Test-Path 'node_modules')) {
59+
$installReason = 'node_modules missing'
60+
} elseif (!(Test-Path $lockHashMarker)) {
61+
$installReason = 'package-lock marker missing'
62+
} elseif ((Get-Content -Path $lockHashMarker -Raw).Trim() -ne (Get-PackageLockHash)) {
63+
$installReason = 'package-lock.json changed'
64+
} elseif (!(Test-Path 'node_modules\electron-updater')) {
65+
$installReason = 'electron-updater missing'
66+
}
67+
68+
if ($null -ne $installReason) {
69+
Install-DesktopDependencies -Reason $installReason
70+
} else {
71+
Write-Host 'Desktop dependencies are up to date.'
72+
}
3673
}
3774

75+
Write-Host 'Building Electron desktop app...'
76+
Push-Location (Join-Path $repoRoot 'apps\dsa-desktop')
77+
Ensure-DesktopDependencies
78+
3879
Write-Host 'Stopping running app (if any)...'
3980
Get-Process -Name "Daily Stock Analysis" -ErrorAction SilentlyContinue | Stop-Process -Force
4081
Get-Process -Name "stock_analysis" -ErrorAction SilentlyContinue | Stop-Process -Force
@@ -47,10 +88,7 @@ if (Test-Path 'dist\win-unpacked') {
4788
$appBuilderPath = 'node_modules\app-builder-bin\win\x64\app-builder.exe'
4889
if (!(Test-Path $appBuilderPath)) {
4990
Write-Host 'app-builder.exe missing, reinstalling dependencies...'
50-
if (Test-Path 'node_modules') {
51-
Remove-Item -Recurse -Force 'node_modules'
52-
}
53-
npm install
91+
Install-DesktopDependencies -Reason 'app-builder.exe missing' -Clean
5492
}
5593

5694
npx electron-builder --win nsis

0 commit comments

Comments
 (0)