@@ -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+
3879Write-Host ' Stopping running app (if any)...'
3980Get-Process - Name " Daily Stock Analysis" - ErrorAction SilentlyContinue | Stop-Process - Force
4081Get-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'
4889if (! (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
5694npx electron- builder -- win nsis
0 commit comments