#Requires -Version 5.1 <# .SYNOPSIS Genera JNC-NetTools.exe con todas las dependencias (PyInstaller). .DESCRIPTION Crea/usa un venv, instala requirements-win.txt y PyInstaller, y construye el .exe. .EXAMPLE .\Build-Windows.ps1 #> $ErrorActionPreference = "Stop" $ProjectRoot = $PSScriptRoot Set-Location $ProjectRoot Write-Host "=== JNC-NetTools - Build Windows ===" -ForegroundColor Cyan Write-Host "" # Detectar Python (evitar stub de Microsoft Store; priorizar "py" o python real) $pythonExe = $null $usePyLauncher = $false # Probar "py" primero (launcher de Python en Windows) $pyCmd = Get-Command py -ErrorAction SilentlyContinue if ($pyCmd) { $pythonExe = "py" $usePyLauncher = $true } if (-not $pythonExe) { foreach ($name in @("python", "python3")) { $c = Get-Command $name -ErrorAction SilentlyContinue if ($c -and $c.Source -and $c.Source -notmatch "WindowsApps\\python") { $pythonExe = $c.Source break } } } # Si solo tenemos el stub de Microsoft Store, no sirve if ($pythonExe -and $pythonExe -match "WindowsApps\\python") { $pythonExe = $null } if (-not $pythonExe) { Write-Host "ERROR: No se encontró Python instalado." -ForegroundColor Red Write-Host " El 'python' de Microsoft Store no es suficiente. Instala Python 3.8+ desde:" -ForegroundColor Yellow Write-Host " https://www.python.org/downloads/" -ForegroundColor White Write-Host " Durante la instalación, marca: 'Add Python to PATH'." -ForegroundColor Yellow exit 1 } Write-Host "[1/5] Python: $pythonExe" -ForegroundColor Green $venvPath = Join-Path $ProjectRoot "venv" $venvPython = Join-Path $venvPath "Scripts\python.exe" $venvPip = Join-Path $venvPath "Scripts\pip.exe" $useVenv = $false if (Test-Path $venvPython) { Write-Host "[2/5] Usando entorno virtual existente: venv\" -ForegroundColor Green $useVenv = $true } else { Write-Host "[2/5] Creando entorno virtual en venv\..." -ForegroundColor Yellow $created = $false if ($usePyLauncher) { $null = & py -3 -m venv $venvPath 2>&1 if (Test-Path $venvPython) { $created = $true } } if (-not $created -and $pythonExe -ne "py" -and $pythonExe -notmatch "WindowsApps") { $null = & $pythonExe -m venv $venvPath 2>&1 if (Test-Path $venvPython) { $created = $true } } if ($created) { $useVenv = $true } else { Write-Host " Venv no disponible; usando Python del sistema." -ForegroundColor Yellow $venvPython = $pythonExe $venvPip = "pip" if ($usePyLauncher) { $venvPip = "py -3 -m pip" } } } # Instalar dependencias Write-Host "[3/5] Instalando dependencias (requirements-win.txt + PyInstaller)..." -ForegroundColor Yellow $reqPath = Join-Path $ProjectRoot "requirements-win.txt" if ($useVenv) { & $venvPip install --quiet --upgrade pip & $venvPip install --quiet -r $reqPath & $venvPip install --quiet pyinstaller } else { if ($usePyLauncher) { & py -3 -m pip install --quiet --upgrade pip & py -3 -m pip install --quiet -r $reqPath & py -3 -m pip install --quiet pyinstaller } else { & $venvPython -m pip install --quiet --upgrade pip & $venvPython -m pip install --quiet -r $reqPath & $venvPython -m pip install --quiet pyinstaller } } if ($LASTEXITCODE -ne 0) { Write-Host "ERROR: Fallo al instalar dependencias." -ForegroundColor Red exit 1 } Write-Host " Dependencias instaladas." -ForegroundColor Green # Limpiar y construir Write-Host "[4/5] Construyendo ejecutable con PyInstaller (puede tardar unos minutos)..." -ForegroundColor Yellow if ($useVenv) { $venvPyinstaller = Join-Path $venvPath "Scripts\pyinstaller.exe" & $venvPyinstaller --clean --noconfirm JNC-NetTools.spec } else { if ($usePyLauncher) { & py -3 -m PyInstaller --clean --noconfirm JNC-NetTools.spec } else { & $venvPython -m PyInstaller --clean --noconfirm JNC-NetTools.spec } } if ($LASTEXITCODE -ne 0) { Write-Host "ERROR: PyInstaller falló." -ForegroundColor Red exit 1 } $exePath = Join-Path $ProjectRoot "dist\JNC-NetTools.exe" Write-Host "[5/5] Verificando salida..." -ForegroundColor Yellow if (-not (Test-Path $exePath)) { Write-Host "ERROR: No se generó dist\JNC-NetTools.exe" -ForegroundColor Red exit 1 } Write-Host "" Write-Host "=== Listo ===" -ForegroundColor Cyan Write-Host "Ejecutable: $exePath" -ForegroundColor Green Write-Host "" Write-Host "Para crear el instalador completo (Npcap + Nmap):" -ForegroundColor Gray Write-Host " 1. Copia npcap-*.exe y nmap-*-win32.zip en installer\extras\" -ForegroundColor Gray Write-Host " 2. Compila installer\installer.iss con Inno Setup" -ForegroundColor Gray Write-Host ""