51 lines
1.7 KiB
PowerShell
51 lines
1.7 KiB
PowerShell
|
|
# Ensure we are in the backend directory
|
||
|
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||
|
|
Set-Location $ScriptDir
|
||
|
|
|
||
|
|
Write-Host "Starting Backend Build Process..." -ForegroundColor Cyan
|
||
|
|
|
||
|
|
# Define paths
|
||
|
|
$VenvPath = Join-Path $ScriptDir "venv"
|
||
|
|
$PythonExe = Join-Path $VenvPath "Scripts\python.exe"
|
||
|
|
$PipExe = Join-Path $VenvPath "Scripts\pip.exe"
|
||
|
|
$PyInstallerExe = Join-Path $VenvPath "Scripts\pyinstaller.exe"
|
||
|
|
$SpecFile = "smartedt_backend.spec"
|
||
|
|
|
||
|
|
# 1. Check/Create Virtual Environment
|
||
|
|
if (-not (Test-Path $VenvPath)) {
|
||
|
|
Write-Host "Virtual environment not found. Creating..." -ForegroundColor Yellow
|
||
|
|
python -m venv venv
|
||
|
|
if ($LASTEXITCODE -ne 0) {
|
||
|
|
Write-Error "Failed to create virtual environment."
|
||
|
|
exit 1
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
Write-Host "Using existing virtual environment." -ForegroundColor Green
|
||
|
|
}
|
||
|
|
|
||
|
|
# 2. Install Dependencies
|
||
|
|
Write-Host "Installing/Updating build dependencies..." -ForegroundColor Yellow
|
||
|
|
& $PipExe install -r requirements.txt
|
||
|
|
& $PipExe install -r requirements_build.txt
|
||
|
|
if ($LASTEXITCODE -ne 0) {
|
||
|
|
Write-Error "Failed to install dependencies."
|
||
|
|
exit 1
|
||
|
|
}
|
||
|
|
|
||
|
|
# 3. Clean previous builds
|
||
|
|
Write-Host "Cleaning up previous builds..." -ForegroundColor Yellow
|
||
|
|
if (Test-Path "dist") { Remove-Item -Recurse -Force "dist" }
|
||
|
|
if (Test-Path "build") { Remove-Item -Recurse -Force "build" }
|
||
|
|
|
||
|
|
# 4. Run PyInstaller
|
||
|
|
Write-Host "Running PyInstaller..." -ForegroundColor Cyan
|
||
|
|
& $PyInstallerExe --clean --noconfirm $SpecFile
|
||
|
|
|
||
|
|
if ($LASTEXITCODE -eq 0) {
|
||
|
|
Write-Host "`nBackend build successful!" -ForegroundColor Green
|
||
|
|
Write-Host "Executable located at: $(Join-Path $ScriptDir 'dist\smartedt_backend\smartedt_backend.exe')" -ForegroundColor Green
|
||
|
|
} else {
|
||
|
|
Write-Error "`nBackend build failed!"
|
||
|
|
exit 1
|
||
|
|
}
|