mirror of
https://github.com/bitwarden/browser
synced 2026-02-12 22:44:11 +00:00
Add support for zipping non safari builds
This commit is contained in:
@@ -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"
|
||||
|
||||
52
apps/browser/scripts/dist.ps1
Executable file
52
apps/browser/scripts/dist.ps1
Executable file
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user