From 366cb638e410936b2c935017db5fb84c9c38e220 Mon Sep 17 00:00:00 2001 From: Miguel Date: Fri, 22 Aug 2025 18:07:19 +0200 Subject: [PATCH] Add PowerShell build script for S7 Streamer & Logger with frontend build, conda activation, and compression steps --- build.ps1 | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ build_all.bat | 0 2 files changed, 99 insertions(+) create mode 100644 build.ps1 delete mode 100644 build_all.bat diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..731cc8e --- /dev/null +++ b/build.ps1 @@ -0,0 +1,99 @@ +# PowerShell Build Script for S7 Streamer & Logger +# Compatible with PowerShell Core and Windows PowerShell + +Write-Host "Starting build process..." -ForegroundColor Green + +# Step 1: Build Frontend +Write-Host "Building frontend..." -ForegroundColor Yellow +Set-Location frontend +try { + npm run build + Write-Host "Frontend build completed" -ForegroundColor Green +} catch { + Write-Host "Frontend build failed: $_" -ForegroundColor Red + exit 1 +} + +# Step 2: Return to root and clean old builds +Set-Location .. +Write-Host "Cleaning old build directories..." -ForegroundColor Yellow + +if (Test-Path "build") { + Remove-Item -Recurse -Force "build" + Write-Host " Removed build directory" -ForegroundColor Gray +} +if (Test-Path "dist") { + Remove-Item -Recurse -Force "dist" + Write-Host " Removed dist directory" -ForegroundColor Gray +} + +# Step 3: Activate conda environment and build with PyInstaller +Write-Host "Activating conda environment and building executable..." -ForegroundColor Yellow +try { + # Activate conda environment + conda activate snap7v12 + + # Run PyInstaller + pyinstaller main.spec --clean + + Write-Host "Build completed successfully!" -ForegroundColor Green + Write-Host "Results available in: dist/main/" -ForegroundColor Cyan +} catch { + Write-Host "PyInstaller build failed: $_" -ForegroundColor Red + exit 1 +} + +# Step 4: Compress the dist/main directory +Write-Host "Compressing distribution..." -ForegroundColor Yellow +$timestamp = Get-Date -Format "yyyyMMdd_HHmmss" +$zipName = "S7_Streamer_Logger_$timestamp.zip" +$destinationPath = "C:\Users\migue\OneDrive\Miguel\CSA - Trabajo\Software\SIDEL\09 - DIET AS REGULAR" + +try { + # Check if destination directory exists + if (-not (Test-Path $destinationPath)) { + Write-Host "Creating destination directory..." -ForegroundColor Yellow + New-Item -ItemType Directory -Path $destinationPath -Force | Out-Null + } + + # Try to use 7zip first (if available) + $sevenZipPaths = @( + "C:\Program Files\7-Zip\7z.exe", + "C:\Program Files (x86)\7-Zip\7z.exe" + ) + + $sevenZipFound = $false + foreach ($path in $sevenZipPaths) { + if (Test-Path $path) { + Write-Host "Using 7zip for compression..." -ForegroundColor Cyan + $zipFullPath = Join-Path $destinationPath $zipName + & "$path" a -tzip "$zipFullPath" ".\dist\main\*" -r + $sevenZipFound = $true + break + } + } + + # If 7zip not found, use PowerShell's built-in compression + if (-not $sevenZipFound) { + Write-Host "Using PowerShell built-in compression..." -ForegroundColor Cyan + $tempZip = ".\$zipName" + Compress-Archive -Path ".\dist\main\*" -DestinationPath $tempZip -Force + + # Move to destination + $zipFullPath = Join-Path $destinationPath $zipName + Move-Item $tempZip $zipFullPath -Force + } + + Write-Host "Archive created successfully!" -ForegroundColor Green + Write-Host "Location: $zipFullPath" -ForegroundColor Cyan + + # Show file size + $fileSize = (Get-Item $zipFullPath).Length / 1MB + Write-Host "Archive size: $([math]::Round($fileSize, 2)) MB" -ForegroundColor Gray + +} catch { + Write-Host "Compression failed: $_" -ForegroundColor Red + exit 1 +} + +Write-Host "Build process completed!" -ForegroundColor Green diff --git a/build_all.bat b/build_all.bat deleted file mode 100644 index e69de29..0000000