From 592e8faf83c6bbb5e97e2c94c2348bcfdfdd3355 Mon Sep 17 00:00:00 2001 From: Alexandr Stelnykovych Date: Sat, 12 Apr 2025 23:17:07 +0300 Subject: [PATCH] [packaging] new helper scripts --- .../windows/dev_helpers/build_angular.ps1 | 79 +++++++++++++++++++ packaging/windows/dev_helpers/build_tauri.ps1 | 38 +++++++++ 2 files changed, 117 insertions(+) create mode 100644 packaging/windows/dev_helpers/build_angular.ps1 create mode 100644 packaging/windows/dev_helpers/build_tauri.ps1 diff --git a/packaging/windows/dev_helpers/build_angular.ps1 b/packaging/windows/dev_helpers/build_angular.ps1 new file mode 100644 index 00000000..0f6768d5 --- /dev/null +++ b/packaging/windows/dev_helpers/build_angular.ps1 @@ -0,0 +1,79 @@ +# This script builds the Angular project for the Portmaster application and packages it into a zip file. +# The script assumes that all necessary dependencies are installed and available. +# Output file: dist/portmaster.zip + +[CmdletBinding()] +param ( + [Parameter(Mandatory=$false)] + [Alias("d")] + [switch]$Development, + + [Parameter(Mandatory=$false)] + [Alias("i")] + [switch]$Interactive +) + +# Store original directory and find project root +$originalDir = Get-Location +$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path +$projectRoot = (Get-Item $scriptDir).Parent.Parent.Parent.FullName + +try { + # Create output directory + $outputDir = Join-Path $scriptDir "dist" + New-Item -ItemType Directory -Path $outputDir -Force | Out-Null + + # Navigate to Angular project + Set-Location (Join-Path $projectRoot "desktop\angular") + + # npm install - always run in non-interactive mode, ask in interactive mode + if (!$Interactive -or (Read-Host "Run 'npm install'? (Y/N, default: Y)") -notmatch '^[Nn]$') { + npm install + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + } + + # build libs - always run in non-interactive mode, ask in interactive mode + if (!$Interactive -or (Read-Host "Build shared libraries? (Y/N, default: Y)") -notmatch '^[Nn]$') { + if ($Development) { + Write-Host "Building shared libraries in development mode" -ForegroundColor Yellow + npm run build-libs:dev + } else { + Write-Host "Building shared libraries in production mode" -ForegroundColor Yellow + npm run build-libs + } + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + } + + # Build Angular project + if ($Development) { + Write-Host "Building Angular project in development mode" -ForegroundColor Yellow + ng build --configuration development --base-href /ui/modules/portmaster/ portmaster + } else { + Write-Host "Building Angular project in production mode" -ForegroundColor Yellow + ng build --configuration production --base-href /ui/modules/portmaster/ portmaster + } + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + + # Create zip archive + Write-Host "Creating zip archive" -ForegroundColor Yellow + Set-Location dist + $destinationZip = Join-Path $outputDir "portmaster.zip" + if ($PSVersionTable.PSVersion.Major -ge 5) { + # Option 1: Use .NET Framework directly (faster than Compress-Archive) + Write-Host "Using System.IO.Compression for faster archiving" -ForegroundColor Yellow + if (Test-Path $destinationZip) { Remove-Item $destinationZip -Force } # Remove existing zip if it exists + Add-Type -AssemblyName System.IO.Compression.FileSystem + $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal + [System.IO.Compression.ZipFile]::CreateFromDirectory((Get-Location), $destinationZip, $compressionLevel, $false) + } + else { + # Fall back to Compress-Archive + Compress-Archive -Path * -DestinationPath $destinationZip -Force + } + + Write-Host "Build completed successfully: $(Join-Path $outputDir "portmaster.zip")" -ForegroundColor Green +} +finally { + # Return to original directory - this will execute even if Ctrl+C is pressed + Set-Location $originalDir +} \ No newline at end of file diff --git a/packaging/windows/dev_helpers/build_tauri.ps1 b/packaging/windows/dev_helpers/build_tauri.ps1 new file mode 100644 index 00000000..c16fc897 --- /dev/null +++ b/packaging/windows/dev_helpers/build_tauri.ps1 @@ -0,0 +1,38 @@ +# This script builds the Tauri application for Portmaster on Windows. +# It optionally builds the required Angular tauri-builtin project first. +# The script assumes that all necessary dependencies (Node.js, Rust, etc.) are installed. +# Output file: dist/portmaster.exe + +# Store original directory and find project root +$originalDir = Get-Location +$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path +$projectRoot = (Get-Item $scriptDir).Parent.Parent.Parent.FullName + +# Create output directory +$outputDir = Join-Path $scriptDir "dist" +New-Item -ItemType Directory -Path $outputDir -Force | Out-Null + +# Ask if user wants to build the Angular tauri-builtin project +if ((Read-Host "Build Angular tauri-builtin project? (Y/N, default: Y)") -notmatch '^[Nn]$') { + # Navigate to Angular project + Set-Location (Join-Path $projectRoot "desktop\angular") + + # Build tauri-builtin project + ng build --configuration production --base-href / tauri-builtin + if ($LASTEXITCODE -ne 0) { Set-Location $originalDir; exit $LASTEXITCODE } +} + +# Navigate to Tauri project directory +Set-Location (Join-Path $projectRoot "desktop\tauri\src-tauri") + +# Build Tauri project for Windows +cargo tauri build --no-bundle +if ($LASTEXITCODE -ne 0) { Set-Location $originalDir; exit $LASTEXITCODE } + +# Copy the output files to the script's dist directory +$tauriOutput = Join-Path (Get-Location) "target\release" +Copy-Item -Path "$tauriOutput\portmaster.exe" -Destination $outputDir -Force + +# Return to original directory +Set-Location $originalDir +Write-Host "Build completed successfully: $outputDir\portmaster.exe" -ForegroundColor Green \ No newline at end of file