plate-config-app/build_exe.ps1

83 lines
3.1 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

param(
[switch]$InstallBuildDeps,
[switch]$CleanOnly
)
$ErrorActionPreference = "Stop"
$projectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $projectRoot
# ── Очистка артефактов сборки ──────────────────────────────────────
function Clean-Build {
$dirs = @("build", "dist")
foreach ($d in $dirs) {
$path = Join-Path $projectRoot $d
if (Test-Path $path) {
Remove-Item $path -Recurse -Force
Write-Host " Удалено: $d"
}
}
# __pycache__ в проекте (без .venv)
Get-ChildItem -Path $projectRoot -Directory -Filter "__pycache__" -Recurse |
Where-Object { $_.FullName -notlike "*\.venv\*" } |
ForEach-Object {
Remove-Item $_.FullName -Recurse -Force
Write-Host " Удалено: $($_.FullName -replace [regex]::Escape($projectRoot), '.')"
}
Write-Host "Очистка завершена."
}
Write-Host "=== Очистка ==="
Clean-Build
if ($CleanOnly) {
exit 0
}
# ── Виртуальное окружение ──────────────────────────────────────────
$venvPython = Join-Path $projectRoot ".venv\Scripts\python.exe"
if (-not (Test-Path $venvPython)) {
throw "Не найдено виртуальное окружение .venv. Создайте его перед сборкой."
}
if ($InstallBuildDeps) {
Write-Host ""
Write-Host "=== Установка зависимостей ==="
& $venvPython -m pip install --upgrade pip
& $venvPython -m pip install -r requirements-build.txt
}
# ── Сборка ─────────────────────────────────────────────────────────
Write-Host ""
Write-Host "=== Сборка EXE ==="
& $venvPython -m PyInstaller --noconfirm --clean plate_config_app.spec
if ($LASTEXITCODE -ne 0) {
throw "PyInstaller завершился с ошибкой (код $LASTEXITCODE)."
}
$exe = Join-Path $projectRoot "dist\plate_config_app.exe"
if (-not (Test-Path $exe)) {
throw "EXE не найден после сборки."
}
# ── Копирование ресурсных папок рядом с EXE ───────────────────────
Write-Host ""
Write-Host "=== Копирование ресурсов ==="
$resourceFolders = @("light_modes", "input_mappings", "commands")
foreach ($folder in $resourceFolders) {
$src = Join-Path $projectRoot $folder
$dst = Join-Path $projectRoot "dist\$folder"
if (Test-Path $src) {
Copy-Item $src -Destination $dst -Recurse -Force
Write-Host " Скопировано: $folder"
} else {
Write-Host " Пропущено (не найдено): $folder" -ForegroundColor Yellow
}
}
$size = [math]::Round((Get-Item $exe).Length / 1MB, 1)
Write-Host ""
Write-Host "Сборка завершена: $exe ($size MB)"