# Build MISF_VOB_Download.exe and install at project root (double-click to run). # Output: \MISF_VOB_Download.exe + _internal\ $ErrorActionPreference = "Stop" $Root = Split-Path -Parent $PSScriptRoot Set-Location $Root Write-Host "=== MISF VOB Download - production build (project root) ===" -ForegroundColor Cyan $PortableChrome = Join-Path $Root "chrome-win\chrome-win\chrome.exe" $PortableDriver = Join-Path $Root "chrome-win\chrome-win\chromedriver.exe" if (-not (Test-Path $PortableChrome)) { throw "Portable Chromium not found: $PortableChrome (required for production build)" } if (-not (Test-Path $PortableDriver)) { Write-Warning "Bundled chromedriver missing: $PortableDriver (will download at runtime)" } else { Write-Host "Using portable Chromium: $PortableChrome" } if (-not (Test-Path ".venv\Scripts\python.exe")) { Write-Host "Creating virtual environment..." python -m venv .venv } $Python = Join-Path $Root ".venv\Scripts\python.exe" & $Python -m pip install --upgrade pip -q & $Python -m pip install -r requirements.txt -q & $Python -m pip install "pyinstaller>=6.10" -q Write-Host "Running PyInstaller..." & $Python -m PyInstaller --noconfirm MISF_VOB_Download.spec if ($LASTEXITCODE -ne 0) { throw "PyInstaller failed with exit code $LASTEXITCODE" } $BuiltExe = Join-Path $Root "dist\MISF_VOB_Download.exe" $BuiltDir = Join-Path $Root "dist\MISF_VOB_Download" $BuiltDirExe = Join-Path $BuiltDir "MISF_VOB_Download.exe" if (Test-Path $BuiltExe) { Write-Host "Installing one-file build to project root..." $ExeDest = Join-Path $Root "MISF_VOB_Download.exe" Get-Process -Name "MISF_VOB_Download" -ErrorAction SilentlyContinue | Stop-Process -Force Start-Sleep -Seconds 1 Copy-Item $BuiltExe $ExeDest -Force Remove-Item $BuiltExe -Force } elseif (Test-Path $BuiltDirExe) { Write-Host "Installing folder build to project root..." $ExeDest = Join-Path $Root "MISF_VOB_Download.exe" Get-Process -Name "MISF_VOB_Download" -ErrorAction SilentlyContinue | Stop-Process -Force Start-Sleep -Seconds 1 $InternalDest = Join-Path $Root "_internal" Copy-Item $BuiltDirExe $ExeDest -Force if (Test-Path $InternalDest) { Remove-Item $InternalDest -Recurse -Force } Move-Item (Join-Path $BuiltDir "_internal") $InternalDest -Force Remove-Item $BuiltDir -Recurse -Force } else { throw "Expected build output not found: $BuiltExe or $BuiltDirExe" } $DistFolder = Join-Path $Root "dist" if (Test-Path $DistFolder) { $remaining = @(Get-ChildItem $DistFolder -Force -ErrorAction SilentlyContinue) if ($remaining.Count -eq 0) { Remove-Item $DistFolder -Force } } $InputDir = Join-Path $Root "Input" $OutputDir = Join-Path $Root "Output" New-Item -ItemType Directory -Force -Path (Join-Path $InputDir "PDFs") | Out-Null New-Item -ItemType Directory -Force -Path $OutputDir | Out-Null Copy-Item (Join-Path $Root "docs\PRODUCTION_README.txt") (Join-Path $Root "README_PRODUCTION.txt") -Force Write-Host "" Write-Host "Build complete." -ForegroundColor Green Write-Host " Run: $ExeDest" Write-Host "" Write-Host "First-time setup:" -ForegroundColor Yellow Write-Host " 1. Copy Input\input.xlsx.example to Input\input.xlsx and fill credentials" Write-Host " 2. Add facility names on the Facilities sheet" Write-Host " 3. Keep chrome-win\ next to the .exe" Write-Host " 4. Double-click MISF_VOB_Download.exe in this folder" Write-Host "" Write-Host 'See README_PRODUCTION.txt. Exe is at project root (no dist folder).'