121 lines
4.0 KiB
PowerShell
121 lines
4.0 KiB
PowerShell
# build.ps1
|
|
# ---------
|
|
# Builds LottoSight into a standalone Windows executable.
|
|
# Output: dist\LottoSight\LottoSight.exe
|
|
#
|
|
# Usage:
|
|
# .\build.ps1 # install deps + build
|
|
# .\build.ps1 -SkipDeps # skip pip install (faster when deps are current)
|
|
# .\build.ps1 -Clean # wipe dist\ and build\ before building
|
|
|
|
param(
|
|
[switch]$Clean,
|
|
[switch]$SkipDeps
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
Set-Location $PSScriptRoot
|
|
|
|
# --- Helpers ------------------------------------------------------------------
|
|
|
|
function Write-Step {
|
|
param([string]$Msg)
|
|
Write-Host ""
|
|
Write-Host (" " + $Msg) -ForegroundColor Cyan
|
|
Write-Host (" " + ("-" * $Msg.Length)) -ForegroundColor DarkGray
|
|
}
|
|
|
|
function Fail {
|
|
param([string]$Msg)
|
|
Write-Host ""
|
|
Write-Host " ERROR: $Msg" -ForegroundColor Red
|
|
Write-Host ""
|
|
exit 1
|
|
}
|
|
|
|
# --- Python check -------------------------------------------------------------
|
|
Write-Step "Checking Python"
|
|
|
|
$pyCmd = Get-Command python -ErrorAction SilentlyContinue
|
|
if (-not $pyCmd) {
|
|
Fail "Python not found. Install Python 3.12+ and add it to PATH."
|
|
}
|
|
|
|
# Use exit code to verify version - avoids string parsing
|
|
python -c "import sys; sys.exit(0 if sys.version_info >= (3,12) else 1)" 2>$null
|
|
if ($LASTEXITCODE -ne 0) {
|
|
$found = python -c "import sys; print(sys.version)"
|
|
Fail "Python 3.12 or higher required. Found: $found"
|
|
}
|
|
|
|
$pyVersion = python -c "import sys; print(sys.version.split()[0])"
|
|
Write-Host " Python $pyVersion OK" -ForegroundColor Green
|
|
|
|
# --- Dependencies -------------------------------------------------------------
|
|
if (-not $SkipDeps) {
|
|
Write-Step "Installing dependencies"
|
|
|
|
python -m pip install --upgrade pip --quiet
|
|
if ($LASTEXITCODE -ne 0) { Fail "pip upgrade failed." }
|
|
|
|
python -m pip install -r requirements.txt pyinstaller --quiet
|
|
if ($LASTEXITCODE -ne 0) { Fail "pip install failed." }
|
|
|
|
Write-Host " All packages up to date OK" -ForegroundColor Green
|
|
} else {
|
|
Write-Host ""
|
|
Write-Host " -SkipDeps: skipping pip install" -ForegroundColor DarkGray
|
|
}
|
|
|
|
# --- Assets -------------------------------------------------------------------
|
|
Write-Step "Checking assets"
|
|
|
|
if (-not (Test-Path "assets\icon.png")) {
|
|
Write-Host " icon.png missing - generating..." -ForegroundColor Yellow
|
|
New-Item -ItemType Directory -Force "assets" | Out-Null
|
|
python -c "from core.exporter import create_icon_png; create_icon_png('assets/icon.png')"
|
|
if ($LASTEXITCODE -ne 0) { Fail "Could not generate icon.png." }
|
|
Write-Host " icon.png created OK" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " assets\icon.png OK" -ForegroundColor Green
|
|
}
|
|
|
|
# --- Clean --------------------------------------------------------------------
|
|
if ($Clean) {
|
|
Write-Step "Cleaning previous build"
|
|
Remove-Item -Recurse -Force "dist", "build" -ErrorAction SilentlyContinue
|
|
Write-Host " dist\ and build\ removed OK" -ForegroundColor Green
|
|
}
|
|
|
|
# --- Build --------------------------------------------------------------------
|
|
Write-Step "Running PyInstaller"
|
|
|
|
python -m PyInstaller lottosight.spec --clean --noconfirm
|
|
if ($LASTEXITCODE -ne 0) { Fail "PyInstaller build failed." }
|
|
|
|
# --- Verify and report --------------------------------------------------------
|
|
Write-Step "Build result"
|
|
|
|
$exePath = "dist\LottoSight\LottoSight.exe"
|
|
$distDir = "dist\LottoSight"
|
|
|
|
if (-not (Test-Path $exePath)) {
|
|
Fail "Expected exe not found at: $exePath"
|
|
}
|
|
|
|
$exeSizeMB = [math]::Round((Get-Item $exePath).Length / 1MB, 1)
|
|
$allFiles = Get-ChildItem $distDir -Recurse
|
|
$dirSizeMB = [math]::Round(($allFiles | Measure-Object -Property Length -Sum).Sum / 1MB, 0)
|
|
$absDir = (Resolve-Path $distDir).Path
|
|
|
|
Write-Host ""
|
|
Write-Host " Build successful!" -ForegroundColor Green
|
|
Write-Host ""
|
|
Write-Host " Executable : $exePath ($exeSizeMB MB)"
|
|
Write-Host " Folder : $absDir"
|
|
Write-Host " Total size : ~$dirSizeMB MB"
|
|
Write-Host ""
|
|
Write-Host " To run the app:" -ForegroundColor Yellow
|
|
Write-Host " .\dist\LottoSight\LottoSight.exe" -ForegroundColor Yellow
|
|
Write-Host ""
|