Files
CloudRecoveryAS/build.ps1

64 lines
2.5 KiB
PowerShell

# Build CloudRestoreAS — PyInstaller onefile portable
$ErrorActionPreference = "Stop"
$Root = $PSScriptRoot
Write-Host "===============================================" -ForegroundColor Cyan
Write-Host "CloudRestoreAS - Build Windows (onefile)" -ForegroundColor Cyan
Write-Host "===============================================" -ForegroundColor Cyan
& "$Root\packaging\scripts\download-bundled-deps.ps1"
# Python de Windows (evitar venv creado desde WSL)
$PythonCandidates = @(
"$env:LOCALAPPDATA\Programs\Python\Python313\python.exe",
"$env:LOCALAPPDATA\Programs\Python\Python312\python.exe",
"$env:LOCALAPPDATA\Programs\Python\Python311\python.exe"
)
$Python = $PythonCandidates | Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $Python) {
throw "No se encontró Python 3.11+ en Windows. Instale desde python.org"
}
Write-Host "Python: $Python" -ForegroundColor Gray
$venvDir = Join-Path $Root "venv-windows"
$venvPython = Join-Path $venvDir "Scripts\python.exe"
if (-not (Test-Path $venvPython)) {
if (Test-Path $venvDir) { Remove-Item -Recurse -Force $venvDir }
& $Python -m venv $venvDir
}
& $venvPython -m pip install --upgrade pip -q
& $venvPython -m pip install -r (Join-Path $Root "requirements-windows.txt") -q
$distDir = Join-Path $Root "dist"
$isUncRoot = $Root -like "\\*"
# PyInstaller no puede usar workpath en UNC (WSL); usar carpeta local en Windows
if ($isUncRoot) {
$buildDir = Join-Path $env:LOCALAPPDATA "Temp\cloudrestore-build"
} else {
$buildDir = Join-Path $Root "build"
}
if (Test-Path $buildDir) {
Remove-Item -Recurse -Force $buildDir -ErrorAction SilentlyContinue
}
New-Item -ItemType Directory -Force -Path $distDir, $buildDir | Out-Null
if (Test-Path (Join-Path $distDir "CloudRestoreAS.exe")) {
Remove-Item -Force (Join-Path $distDir "CloudRestoreAS.exe") -ErrorAction SilentlyContinue
}
Write-Host "Ejecutando PyInstaller (onefile)..." -ForegroundColor Yellow
Write-Host "Workpath: $buildDir" -ForegroundColor Gray
& $venvPython -m PyInstaller (Join-Path $Root "packaging\CloudRestoreAS.spec") `
--clean --noconfirm `
--distpath $distDir `
--workpath $buildDir
$exe = Join-Path $Root "dist\CloudRestoreAS.exe"
if (Test-Path $exe) {
Write-Host ""
Write-Host "Build OK: $exe" -ForegroundColor Green
Write-Host "Distribuir solo el .exe; al ejecutar crea config/ automaticamente." -ForegroundColor Cyan
} else {
Write-Host "Error: no se genero el ejecutable" -ForegroundColor Red
exit 1
}