-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_executable.ps1
More file actions
75 lines (66 loc) · 2.81 KB
/
Copy pathbuild_executable.ps1
File metadata and controls
75 lines (66 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Script para empaquetar la aplicación Flask en un ejecutable (Windows / PowerShell)
$ErrorActionPreference = "Stop"
Write-Host "Empaquetando aplicación Flask en ejecutable..." -ForegroundColor Green
Write-Host ""
# Verificar que PyInstaller está instalado
try {
$null = pyinstaller --version
} catch {
Write-Host "PyInstaller no está instalado." -ForegroundColor Red
Write-Host " Instálalo con: pip install pyinstaller" -ForegroundColor Yellow
exit 1
}
# Verificar que Flask está instalado
try {
python -c "import flask" 2>$null
if ($LASTEXITCODE -ne 0) { throw "Flask no instalado" }
} catch {
Write-Host "Flask no está instalado." -ForegroundColor Red
Write-Host " Instala las dependencias con: pip install -r requirements.txt" -ForegroundColor Yellow
exit 1
}
# Preservar .env en dist si existe (no borrarlo)
$envBackup = ".env.dist.backup"
$distEnvPath = Join-Path "dist" ".env"
if (Test-Path $distEnvPath) {
Write-Host "Preservando .env existente en dist..." -ForegroundColor Yellow
Copy-Item -Path $distEnvPath -Destination $envBackup -Force
}
# Limpiar builds anteriores
Write-Host "Limpiando builds anteriores..." -ForegroundColor Yellow
if (Test-Path "build") { Remove-Item -Recurse -Force "build" }
if (Test-Path "dist") { Remove-Item -Recurse -Force "dist" }
Get-ChildItem -Recurse -Directory -Filter "__pycache__" -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
Get-ChildItem -Recurse -Filter "*.pyc" -ErrorAction SilentlyContinue | Remove-Item -Force -ErrorAction SilentlyContinue
# Crear el ejecutable
Write-Host "Creando ejecutable con PyInstaller..." -ForegroundColor Yellow
pyinstaller build_app.spec
if ($LASTEXITCODE -ne 0) {
Write-Host "Error al crear el ejecutable." -ForegroundColor Red
exit 1
}
# En Windows el ejecutable tiene extensión .exe
$exeName = "DJ_CUCHI_app.exe"
$exePath = Join-Path "dist" $exeName
if (Test-Path $exePath) {
# Restaurar .env en dist si se había preservado
if (Test-Path $envBackup) {
$distEnvPath = Join-Path "dist" ".env"
Copy-Item -Path $envBackup -Destination $distEnvPath -Force
Remove-Item $envBackup -Force
Write-Host ".env restaurado en dist." -ForegroundColor Green
}
Write-Host ""
Write-Host "Ejecutable creado correctamente." -ForegroundColor Green
Write-Host ""
Write-Host "Ubicación: $(Resolve-Path $exePath)" -ForegroundColor Cyan
Write-Host ""
Write-Host "Para ejecutar desde PowerShell:" -ForegroundColor Yellow
Write-Host " .\dist\$exeName" -ForegroundColor White
Write-Host ""
Write-Host "El ejecutable abrirá automáticamente el navegador en http://127.0.0.1:5000" -ForegroundColor Gray
Write-Host ""
} else {
Write-Host "Error: No se pudo crear el ejecutable." -ForegroundColor Red
exit 1
}