@echo off setlocal ENABLEDELAYEDEXPANSION cd /d %~dp0 :: Windows Installer Builder for Bible App :: Creates a proper Windows installer (.exe) that can be installed like any other program :: Automatically uninstalls old versions before installing new ones echo === Bible App Windows Installer Builder === echo. where node >nul 2>&1 if errorlevel 1 ( echo. echo ERROR: Node.js is not installed. Please install Node LTS from https://nodejs.org and run this again. pause exit /b 1 ) :: Install dependencies (safe to re-run) echo Installing/updating dependencies... call npm install --no-audit --no-fund if errorlevel 1 ( echo. echo ERROR: npm install failed. Fix errors above and re-run. pause exit /b 1 ) :: Automatically increment version number echo. echo Updating version number... for /f %%i in ('node -p "require('./package.json').version"') do set OLD_VERSION=%%i echo Current version: %OLD_VERSION% :: Use Node.js to increment the patch version (e.g., 1.0.6 -> 1.0.7) node -e "const fs=require('fs');const pkg=JSON.parse(fs.readFileSync('package.json','utf8'));const v=pkg.version.split('.');v[2]=parseInt(v[2])+1;pkg.version=v.join('.');fs.writeFileSync('package.json',JSON.stringify(pkg,null,2)+'\n');console.log(pkg.version);" > new-version.txt set /p NEW_VERSION=nul 2>&1 echo New version: %NEW_VERSION% echo Version updated in package.json :: No build number is stamped into app.js: the version lives in package.json ONLY, and About reads it :: from the running app (app.getVersion). This step used to rewrite a "Build: x.y.z" header comment and :: a matching console.log in app.js, and aborted the whole build when it could not find them — which is :: exactly what happened once that hand-typed header was removed. Nothing to update here any more. echo. :: Ensure VC++ redistributable is bundled for local AI on fresh Windows installs if not exist "vendor\redist\vc_redist.x64.exe" ( echo Downloading Microsoft Visual C++ 2015-2022 x64 redistributable... powershell -NoProfile -Command "New-Item -ItemType Directory -Force -Path 'vendor/redist' | Out-Null; Invoke-WebRequest -Uri 'https://aka.ms/vs/17/release/vc_redist.x64.exe' -OutFile 'vendor/redist/vc_redist.x64.exe' -UseBasicParsing" if errorlevel 1 ( echo WARNING: Failed to download VC++ redistributable. Local AI may not work on fresh Windows PCs. ) ) :: Get app version from package.json (should be the new version) set APP_VERSION=%NEW_VERSION% echo Building installer for Bible App version %APP_VERSION%... echo. :: Stop any running instances. :: The executable is named from productName ("Bible App"), so it is "Bible App.exe" WITH A SPACE. :: This step used to target "BibleApp.exe", which has never existed — so a build started while the :: app was running (the normal state on the TV machine, where it launches at startup) was not :: stopped at all and electron-builder failed later on a locked file instead. echo Stopping any running Bible App... taskkill /F /IM "Bible App.exe" /T >nul 2>&1 taskkill /F /IM BibleApp.exe /T >nul 2>&1 timeout /T 1 >nul 2>&1 :: Check for Developer Mode (allows symlinks without admin) echo Checking Windows Developer Mode... reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /v AllowDevelopmentWithoutDevLicense >nul 2>&1 if errorlevel 1 ( echo. echo WARNING: Developer Mode may not be enabled. echo. echo To fix symlink permission errors, enable Developer Mode: echo 1. Open Windows Settings echo 2. Go to Privacy ^& Security ^> For developers echo 3. Enable "Developer Mode" echo 4. Restart this script echo. echo Alternatively, run this script as Administrator. echo. timeout /T 3 >nul ) :: Clear electron-builder cache if it exists (fixes symlink permission issues) echo Clearing electron-builder cache... powershell -Command "if (Test-Path \"$env:LOCALAPPDATA\electron-builder\Cache\") { Remove-Item -Path \"$env:LOCALAPPDATA\electron-builder\Cache\" -Recurse -Force -ErrorAction SilentlyContinue; Write-Host \"Cache cleared\" }" :: Also specifically clear winCodeSign cache powershell -Command "if (Test-Path \"$env:LOCALAPPDATA\electron-builder\Cache\winCodeSign\") { Remove-Item -Path \"$env:LOCALAPPDATA\electron-builder\Cache\winCodeSign\" -Recurse -Force -ErrorAction SilentlyContinue; Write-Host \"winCodeSign cache cleared\" }" :: Disable code signing completely to avoid symlink permission issues set CSC_IDENTITY_AUTO_DISCOVERY=false set WIN_CSC_LINK= set SKIP_NOTARIZATION=true set CSC_LINK= set CSC_KEY_PASSWORD= set CSC_KEYCHAIN= :: Build the installer (call electron-builder directly with env vars set) echo Building Windows installer... echo. :: Start a background process to continuously clear winCodeSign cache directories call npx electron-builder --win set BUILDER_EXIT=%ERRORLEVEL% echo AFTER BUILDER EXIT CODE: %BUILDER_EXIT% :: Stop the background cache cleaner (don't let taskkill's exit code mask the real result) taskkill /F /IM powershell.exe /FI "WINDOWTITLE eq monitor" >nul 2>&1 if not "%BUILDER_EXIT%"=="0" ( echo. echo ERROR: Build failed - electron-builder exit code %BUILDER_EXIT%. echo. echo If you saw symlink errors, try: echo 1. Enable Developer Mode: Win+I ^> Privacy ^& Security ^> For developers ^> Enable Developer Mode echo 2. Restart your computer echo 3. Run this script again echo. pause exit /b 1 ) echo. echo ======================================== echo Build complete! echo ======================================== echo. echo The installer has been created in the 'dist-installer' folder. echo Installer filename: Bible App Setup %APP_VERSION%.exe echo. echo You can now distribute this installer to any Windows machine. echo When run, it will automatically uninstall any old versions before installing. echo. :: Open the output folder if exist "dist-installer" ( echo Opening output folder... start "" explorer "dist-installer" ) else ( echo WARNING: dist-installer folder not found. Build may have failed. ) echo. pause endlocal