aboutsummaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-12-18 16:46:00 -0500
committerGitHub <noreply@github.com>2020-12-18 16:46:00 -0500
commit0d0728fac0efa567af4da26aa4954829a6ea21a1 (patch)
treeec4acd3aea1d54d94cdb3586b1aedaa02b2d41d5 /dev
parent51223abfa696c5917828fdb5a6d7b1816d76c5c6 (diff)
Build exclude files (#1125)
* Add support for excluding files from the build process * Delete existing file before creating .zip * Exclude sw.js from non-MV3 builds
Diffstat (limited to 'dev')
-rw-r--r--dev/build.js38
-rw-r--r--dev/data/manifest-variants.json14
2 files changed, 46 insertions, 6 deletions
diff --git a/dev/build.js b/dev/build.js
index 3d0a427b..df38e2a4 100644
--- a/dev/build.js
+++ b/dev/build.js
@@ -27,15 +27,18 @@ function clone(value) {
return JSON.parse(JSON.stringify(value));
}
-async function createZip(directory, outputFileName, sevenZipExes=[], onUpdate=null) {
+async function createZip(directory, excludeFiles, outputFileName, sevenZipExes=[], onUpdate=null) {
+ fs.unlinkSync(outputFileName);
for (const exe of sevenZipExes) {
try {
+ const excludeArguments = excludeFiles.map((excludeFilePath) => `-x!${excludeFilePath}`);
childProcess.execFileSync(
exe,
[
'a',
outputFileName,
- '.'
+ '.',
+ ...excludeArguments
],
{
cwd: directory
@@ -46,12 +49,13 @@ async function createZip(directory, outputFileName, sevenZipExes=[], onUpdate=nu
// NOP
}
}
- return await createJSZip(directory, outputFileName, onUpdate);
+ return await createJSZip(directory, excludeFiles, outputFileName, onUpdate);
}
-async function createJSZip(directory, outputFileName, onUpdate) {
+async function createJSZip(directory, excludeFiles, outputFileName, onUpdate) {
const JSZip = util.JSZip;
const files = getAllFiles(directory, directory);
+ removeItemsFromArray(files, excludeFiles);
const zip = new JSZip();
for (const fileName of files) {
zip.file(
@@ -75,6 +79,27 @@ async function createJSZip(directory, outputFileName, onUpdate) {
fs.writeFileSync(outputFileName, data, {encoding: null, flag: 'w'});
}
+function removeItemsFromArray(array, removeItems) {
+ for (const item of removeItems) {
+ const index = getIndexOfFilePath(array, item);
+ if (index >= 0) {
+ array.splice(index, 1);
+ }
+ }
+}
+
+function getIndexOfFilePath(array, item) {
+ const pattern = /\\/g;
+ const separator = '/';
+ item = item.replace(pattern, separator);
+ for (let i = 0, ii = array.length; i < ii; ++i) {
+ if (array[i].replace(pattern, separator) === item) {
+ return i;
+ }
+ }
+ return -1;
+}
+
function applyModifications(manifest, modifications) {
if (Array.isArray(modifications)) {
for (const modification of modifications) {
@@ -271,6 +296,9 @@ async function build(manifest, buildDir, extDir, manifestPath, variantMap, varia
if (typeof variant === 'undefined') { continue; }
const {name, fileName, fileCopies} = variant;
+ let {excludeFiles} = variant;
+ if (!Array.isArray(excludeFiles)) { excludeFiles = []; }
+
process.stdout.write(`Building ${name}...\n`);
const modifiedManifest = createVariantManifest(manifest, variant, variantMap);
@@ -278,7 +306,7 @@ async function build(manifest, buildDir, extDir, manifestPath, variantMap, varia
const fileNameSafe = path.basename(fileName);
const fullFileName = path.join(buildDir, fileNameSafe);
fs.writeFileSync(manifestPath, createManifestString(modifiedManifest));
- await createZip(extDir, fullFileName, sevenZipExes, onUpdate);
+ await createZip(extDir, excludeFiles, fullFileName, sevenZipExes, onUpdate);
if (Array.isArray(fileCopies)) {
for (const fileName2 of fileCopies) {
diff --git a/dev/data/manifest-variants.json b/dev/data/manifest-variants.json
index 0532ab9b..43d06032 100644
--- a/dev/data/manifest-variants.json
+++ b/dev/data/manifest-variants.json
@@ -108,7 +108,10 @@
"variants": [
{
"name": "chrome",
- "fileName": "yomichan-chrome.zip"
+ "fileName": "yomichan-chrome.zip",
+ "excludeFiles": [
+ "sw.js"
+ ]
},
{
"name": "chrome-dev",
@@ -128,6 +131,9 @@
"patternFlags": "",
"replacement": "$1. This is a development build; get the stable version here: https://tinyurl.com/yaatdjmp"
}
+ ],
+ "excludeFiles": [
+ "sw.js"
]
},
{
@@ -179,6 +185,9 @@
}
}
}
+ ],
+ "excludeFiles": [
+ "sw.js"
]
},
{
@@ -205,6 +214,9 @@
"path": ["browser_specific_settings", "gecko", "id"],
"value": "alex.testing@foosoft.net"
}
+ ],
+ "excludeFiles": [
+ "sw.js"
]
}
]