PCM_Report/build.ps1

64 lines
1.9 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

Param(
[switch]$OneFile = $false,
[string]$Name = "DocxCreator"
)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
# Go to script directory
Set-Location -Path $PSScriptRoot
# 1) Create/activate venv
if (-not (Test-Path .\.venv)) {
python -m venv .venv
}
. .\.venv\Scripts\Activate.ps1
# 2) Install deps
pip install --upgrade pip > $null
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pyinstaller
# 3) Ensure default.json exists (copy from config.json if present)
if ((Test-Path .\config.json) -and -not (Test-Path .\default.json)) {
Copy-Item .\config.json .\default.json -Force
}
# 4) Build
Write-Host "Building with PyInstaller..." -ForegroundColor Yellow
# 首先清理旧的构建文件
Write-Host "Cleaning old build files..." -ForegroundColor Yellow
# 尝试优雅地清理,如果失败则跳过
try {
if (Test-Path .\build) {
Remove-Item .\build -Recurse -Force -ErrorAction Stop
Write-Host "Removed build directory" -ForegroundColor Green
}
} catch {
Write-Host "Warning: Could not remove build directory (may be in use)" -ForegroundColor Yellow
}
try {
if (Test-Path .\dist) {
Remove-Item .\dist -Recurse -Force -ErrorAction Stop
Write-Host "Removed dist directory" -ForegroundColor Green
}
} catch {
Write-Host "Warning: Could not remove dist directory (may be in use)" -ForegroundColor Yellow
Write-Host "Continuing with build anyway..." -ForegroundColor Yellow
}
# 使用修复的spec文件构建
if ($OneFile) {
Write-Host "OneFile mode not recommended for PySide6 apps due to DLL issues" -ForegroundColor Yellow
Write-Host "Using OneDir mode instead..." -ForegroundColor Yellow
}
# 总是使用OneDir模式因为PySide6的DLL依赖问题
pyinstaller --noconfirm --clean .\docx_creator_fixed.spec
Write-Host "Build complete. Output at: $(Join-Path $PSScriptRoot 'dist')\$Name" -ForegroundColor Green