Files
Button/sshDeploy/build-gui.ps1
T
2026-07-28 15:33:07 +03:00

78 lines
1.7 KiB
PowerShell

param(
[switch]$OneFile = $true
)
$ErrorActionPreference = 'Stop'
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $here
$pyCmd = $null
if (Get-Command python -ErrorAction SilentlyContinue) {
$pyCmd = @('python')
} elseif (Get-Command py -ErrorAction SilentlyContinue) {
$pyCmd = @('py', '-3')
}
if (-not $pyCmd) {
Write-Host "[error] Python 3 not found." -ForegroundColor Red
exit 1
}
$pyExe = $pyCmd[0]
$pyArgs = @()
if ($pyCmd.Length -gt 1) {
$pyArgs = $pyCmd[1..($pyCmd.Length - 1)]
}
$checkArgs = $pyArgs + @('-m', 'PyInstaller', '--version')
try {
& $pyExe @checkArgs *> $null
} catch {
Write-Host "[error] PyInstaller not found. Install with: py -3 -m pip install pyinstaller" -ForegroundColor Red
exit 1
}
$releaseDir = Join-Path $here 'dist\sshDeploy-gui'
$pyiDist = Join-Path $here 'dist-pyinstaller'
if (Test-Path $releaseDir) { Remove-Item $releaseDir -Recurse -Force }
if (Test-Path $pyiDist) { Remove-Item $pyiDist -Recurse -Force }
$args = @(
'--noconfirm',
'--clean',
'--name', 'sshDeploy-gui',
'--distpath', $pyiDist
)
if ($OneFile) { $args += '--onefile' }
$args += 'gui_app.py'
& $pyExe @pyArgs -m PyInstaller @args
New-Item -ItemType Directory -Force -Path $releaseDir | Out-Null
$artifacts = @(
'config.json',
'config.example.json',
'README.md',
'plink.exe',
'pscp.exe'
)
foreach ($name in $artifacts) {
$src = Join-Path $here $name
if (Test-Path $src) {
Copy-Item $src $releaseDir -Force
}
}
$builtExe = Join-Path $pyiDist 'sshDeploy-gui.exe'
if (Test-Path $builtExe) {
Copy-Item $builtExe (Join-Path $releaseDir 'sshDeploy-gui.exe') -Force
}
if (Test-Path $pyiDist) {
Remove-Item $pyiDist -Recurse -Force
}
Write-Host "[ok] Ready: $releaseDir" -ForegroundColor Green