From 1d91301b2e80e833a4a9e5f2596b7ac65b01693f Mon Sep 17 00:00:00 2001 From: Hinton Date: Tue, 5 Nov 2024 15:59:47 +0100 Subject: [PATCH] Add support for zipping non safari builds --- apps/browser/package.json | 10 +++--- apps/browser/scripts/dist.ps1 | 52 ++++++++++++++++++++++++++++++++ apps/browser/webpack/manifest.js | 9 +++--- 3 files changed, 61 insertions(+), 10 deletions(-) create mode 100755 apps/browser/scripts/dist.ps1 diff --git a/apps/browser/package.json b/apps/browser/package.json index a859073d9a0..9fcd111c83a 100644 --- a/apps/browser/package.json +++ b/apps/browser/package.json @@ -19,11 +19,11 @@ "build:prod:firefox": "cross-env NODE_ENV=production NODE_OPTIONS=\"--max-old-space-size=4096\" npm run build:firefox", "build:prod:opera": "cross-env NODE_ENV=production NODE_OPTIONS=\"--max-old-space-size=4096\" npm run build:opera", "build:prod:safari": "cross-env NODE_ENV=production NODE_OPTIONS=\"--max-old-space-size=4096\" npm run build:safari", - "dist:chrome": "npm run build:prod:chrome", - "dist:edge": "npm run build:prod:edge", - "dist:firefox": "npm run build:prod:firefox", - "dist:opera": "npm run build:prod:opera", - "dist:safari": "npm run build:prod:safari", + "dist:chrome": "npm run build:prod:chrome && ./scripts/dist.ps1 chrome", + "dist:edge": "npm run build:prod:edge && ./scripts/dist.ps1 edge", + "dist:firefox": "npm run build:prod:firefox && ./scripts/dist.ps1 firefox", + "dist:opera": "npm run build:prod:opera && ./scripts/dist.ps1 opera", + "dist:safari": "npm run build:prod:safari && ./scripts/dist.ps1 safari", "test": "jest", "test:watch": "jest --watch", "test:watch:all": "jest --watchAll" diff --git a/apps/browser/scripts/dist.ps1 b/apps/browser/scripts/dist.ps1 new file mode 100755 index 00000000000..3f687586172 --- /dev/null +++ b/apps/browser/scripts/dist.ps1 @@ -0,0 +1,52 @@ +#!/usr/bin/env pwsh + +#### +# Performs the last step of the build process, zipping the built files. For Mac, it also builds the safari extension. +#### + +param ( + [Parameter(Mandatory = $false)] + [String] $browser +) + +if (-not $browser) { + $browser = $env:BROWSER + if (-not $browser) { + Write-Error "Missing mandatory Browser environment variable." + exit 1 + } + + if ($browser -notin 'chrome', 'edge', 'firefox', 'opera', 'safari') { + Write-Error "Invalid browser specified. Valid options are: chrome, edge, firefox, opera, safari." + exit 1 + } +} + +$buildDir = Join-Path $PSScriptRoot "..\build" +$distDir = Join-Path $PSScriptRoot "..\dist" + +Write-Output $PSScriptRoot + +if (-not (Test-Path $buildDir)) { + Write-Output "No build directory found. Exiting..." + exit +} + +# Create dist directory if it doesn't exist +if (-not (Test-Path $distDir)) { + New-Item -ItemType Directory -Path $distDir +} + +if ($browser -ne 'safari') { + $distPath = Join-Path $distDir "dist-$browser.zip" + + if (Test-Path $distPath) { + Remove-Item $distPath + } + + # Compress build directory + if (Test-Path $buildDir) { + Compress-Archive -Path $buildDir -DestinationPath $distPath + Write-Output "Zipped $buildDir into $distPath" + } +} diff --git a/apps/browser/webpack/manifest.js b/apps/browser/webpack/manifest.js index fedc9b84c79..cf8296707bb 100644 --- a/apps/browser/webpack/manifest.js +++ b/apps/browser/webpack/manifest.js @@ -30,7 +30,7 @@ function transform(browser) { }; } -const browsers = ["chrome", "firefox", "opera", "edge", "safari"]; +const browsers = ["chrome", "edge", "firefox", "opera", "safari"]; /** * Flatten the browser prefixes in the manifest. @@ -44,8 +44,7 @@ function transformPrefixes(manifest, browser) { function transformObject(obj) { return Object.keys(obj).reduce((acc, key) => { // Determine if we need to recurse into the object. - const isObjectNotArray = - typeof obj[key] === "object" && obj[key] !== null && !Array.isArray(obj[key]); + const nested = typeof obj[key] === "object" && obj[key] !== null && !Array.isArray(obj[key]); if (key.startsWith(prefix)) { const newKey = key.slice(prefix.length); @@ -56,9 +55,9 @@ function transformPrefixes(manifest, browser) { return acc; } - acc[newKey] = isObjectNotArray ? transformObject(obj[key]) : obj[key]; + acc[newKey] = nested ? transformObject(obj[key]) : obj[key]; } else if (!browsers.some((b) => key.startsWith(`__${b}__`))) { - acc[key] = isObjectNotArray ? transformObject(obj[key]) : obj[key]; + acc[key] = nested ? transformObject(obj[key]) : obj[key]; } return acc;