98 lines
3.3 KiB
PowerShell
98 lines
3.3 KiB
PowerShell
# CpyGateway PowerShell Build Script
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "CpyGateway Build Script" -ForegroundColor Cyan
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# Check Python
|
|
Write-Host "[1/6] Checking Python..." -ForegroundColor Yellow
|
|
try {
|
|
$pythonVersion = python --version 2>&1
|
|
Write-Host "Python version: $pythonVersion" -ForegroundColor Green
|
|
} catch {
|
|
Write-Host "[ERROR] Python not found. Please install Python first." -ForegroundColor Red
|
|
Read-Host "Press Enter to exit"
|
|
exit 1
|
|
}
|
|
Write-Host ""
|
|
|
|
# Check pip
|
|
Write-Host "[2/6] Checking pip..." -ForegroundColor Yellow
|
|
try {
|
|
$pipVersion = pip --version 2>&1
|
|
Write-Host "pip version: $pipVersion" -ForegroundColor Green
|
|
} catch {
|
|
Write-Host "[ERROR] pip not found" -ForegroundColor Red
|
|
Read-Host "Press Enter to exit"
|
|
exit 1
|
|
}
|
|
Write-Host ""
|
|
|
|
# Install/Update PyInstaller
|
|
Write-Host "[3/6] Installing/Updating PyInstaller..." -ForegroundColor Yellow
|
|
try {
|
|
pip install --upgrade pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple
|
|
Write-Host "PyInstaller installed/updated successfully" -ForegroundColor Green
|
|
} catch {
|
|
Write-Host "[ERROR] Failed to install PyInstaller" -ForegroundColor Red
|
|
Read-Host "Press Enter to exit"
|
|
exit 1
|
|
}
|
|
Write-Host ""
|
|
|
|
# Install dependencies
|
|
Write-Host "[4/6] Installing dependencies..." -ForegroundColor Yellow
|
|
try {
|
|
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
|
|
Write-Host "Dependencies installed successfully" -ForegroundColor Green
|
|
} catch {
|
|
Write-Host "[ERROR] Failed to install dependencies" -ForegroundColor Red
|
|
Read-Host "Press Enter to exit"
|
|
exit 1
|
|
}
|
|
Write-Host ""
|
|
|
|
# Clean old build files
|
|
Write-Host "[5/6] Cleaning old build files..." -ForegroundColor Yellow
|
|
if (Test-Path "build") {
|
|
Remove-Item -Path "build" -Recurse -Force
|
|
Write-Host "Removed build directory" -ForegroundColor Gray
|
|
}
|
|
if (Test-Path "dist") {
|
|
Remove-Item -Path "dist" -Recurse -Force
|
|
Write-Host "Removed dist directory" -ForegroundColor Gray
|
|
}
|
|
Write-Host "Cleanup completed" -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
# Build
|
|
Write-Host "[6/6] Building..." -ForegroundColor Yellow
|
|
try {
|
|
# 读取版本号
|
|
$version = python -c "from version import get_version; print(get_version())"
|
|
pyinstaller CpyGateway.spec
|
|
Write-Host "Build successful" -ForegroundColor Green
|
|
} catch {
|
|
Write-Host "[ERROR] Build failed" -ForegroundColor Red
|
|
Read-Host "Press Enter to exit"
|
|
exit 1
|
|
}
|
|
Write-Host ""
|
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "Build completed!" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
Write-Host "Executable location: dist\CpyGateway_v$version.exe" -ForegroundColor White
|
|
Write-Host ""
|
|
Write-Host "Deployment instructions:" -ForegroundColor Yellow
|
|
Write-Host "1. Copy dist folder to target computer" -ForegroundColor White
|
|
Write-Host "2. Ensure MATLAB Runtime is installed (if needed)" -ForegroundColor White
|
|
Write-Host "3. Modify config.json as needed" -ForegroundColor White
|
|
Write-Host "4. Double-click CpyGateway_v$version.exe to run" -ForegroundColor White
|
|
Write-Host ""
|
|
Read-Host "Press Enter to exit"
|