|
| 1 | +param( |
| 2 | + [Parameter(Mandatory = $true)] |
| 3 | + [ValidateSet("windows", "windows-cublas", "linux", "linux-cublas", "macos", "macos-metal")] |
| 4 | + [string]$BuildPlatform, |
| 5 | + |
| 6 | + [Parameter(Mandatory = $false)] |
| 7 | + [switch]$Force, |
| 8 | + |
| 9 | + [Parameter(Mandatory = $false)] |
| 10 | + [switch]$SkipDeployment, |
| 11 | + |
| 12 | + [Parameter(Mandatory = $false)] |
| 13 | + [switch]$SkipNpmInstall |
| 14 | +) |
| 15 | + |
| 16 | +try { |
| 17 | + # Clean up the previous build artifacts |
| 18 | + |
| 19 | + if ($Force) { |
| 20 | + Write-Host "Cleaning previous build artifacts..." |
| 21 | + Remove-Item -Recurse -Force -ErrorAction SilentlyContinue node_modules |
| 22 | + Remove-Item -Recurse -Force -ErrorAction SilentlyContinue dist |
| 23 | + } |
| 24 | + |
| 25 | + # Determine architecture based on platform |
| 26 | + $platform = "" |
| 27 | + switch ($BuildPlatform) { |
| 28 | + "windows" { |
| 29 | + $platform = "win32" |
| 30 | + } |
| 31 | + "windows-cublas" { |
| 32 | + $platform = "win32" |
| 33 | + } |
| 34 | + "linux" { |
| 35 | + $platform = "linux" |
| 36 | + } |
| 37 | + "linux-cublas" { |
| 38 | + $platform = "linux" |
| 39 | + } |
| 40 | + "macos" { |
| 41 | + } # For universal macOS build |
| 42 | + "macos-metal" { |
| 43 | + } # For universal macOS build |
| 44 | + default { |
| 45 | + throw "Unsupported platform: $BuildPlatform" |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + if (-not $SkipNpmInstall) { |
| 50 | + |
| 51 | + # Install dependencies |
| 52 | + Write-Host "Installing Node dependencies..." |
| 53 | + # skip dev dependencies on linux platform |
| 54 | + if ($platform -eq "linux") { |
| 55 | + npm ci --cache .npm --prefer-offline --production |
| 56 | + } |
| 57 | + else { |
| 58 | + npm ci --cache .npm --prefer-offline |
| 59 | + } |
| 60 | + |
| 61 | + if ($LASTEXITCODE -ne 0) { |
| 62 | + throw "npm install failed" |
| 63 | + } |
| 64 | + # # Conditional appdmg installation for macOS builds |
| 65 | + # # if ($BuildPlatform -eq "macos" -or $BuildPlatform -eq "macos-metal") { |
| 66 | + # if ($BuildPlatform -eq "macos-metal") { |
| 67 | + # Write-Host "Installing appdmg for macOS..." |
| 68 | + # npm install appdmg --save-dev |
| 69 | + # if ($LASTEXITCODE -ne 0) { |
| 70 | + # throw "npm install appdmg failed" |
| 71 | + # } |
| 72 | + # } |
| 73 | + } |
| 74 | + # Build the project |
| 75 | + Write-Host "Building the project..." |
| 76 | + npm run build |
| 77 | + if ($LASTEXITCODE -ne 0) { |
| 78 | + throw "npm run build failed" |
| 79 | + } |
| 80 | + |
| 81 | + if ($SkipDeployment) { |
| 82 | + Write-Warning "Skipping deployment..." |
| 83 | + } |
| 84 | + else { |
| 85 | + # Copy the dist folder to wingman.cpp if the ../services/wingman.cpp/wingman folder exists |
| 86 | + $distRoot = "../services/wingman.cpp/wingman" |
| 87 | + if (Test-Path $distRoot) { |
| 88 | + Write-Host "Copying dist folder to wingman.cpp..." |
| 89 | + Copy-Item -Recurse -Force -ErrorAction SilentlyContinue ./dist ../services/wingman.cpp/wingman/distadmin |
| 90 | + } |
| 91 | + else { |
| 92 | + Write-Warning "wingman.cpp folder not found. Skipping copy of dist folder..." |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + Write-Host "UX $command completed successfully." |
| 97 | +} |
| 98 | +catch { |
| 99 | + Write-Error "An error occurred during the UX build process: $_" |
| 100 | + exit 1 |
| 101 | +} |
0 commit comments