aboutsummaryrefslogtreecommitdiff
path: root/scripts/build/buildWeb.mjs
diff options
context:
space:
mode:
authorRoman / Linnea Gräf <romangraef@gmail.com>2022-12-01 19:16:09 +0100
committerGitHub <noreply@github.com>2022-12-01 19:16:09 +0100
commit0ff6d3dd4168ee72f9216cfcccc9307bae5b25a7 (patch)
tree5f742d86dc9995615a241a210fc70a62cd82ecd0 /scripts/build/buildWeb.mjs
parent734054ff68a103482bff903bb384bc24576c5499 (diff)
downloadVencord-0ff6d3dd4168ee72f9216cfcccc9307bae5b25a7.tar.gz
Vencord-0ff6d3dd4168ee72f9216cfcccc9307bae5b25a7.tar.bz2
Vencord-0ff6d3dd4168ee72f9216cfcccc9307bae5b25a7.zip
Add Firefox extension build (#277)
Diffstat (limited to 'scripts/build/buildWeb.mjs')
-rwxr-xr-xscripts/build/buildWeb.mjs53
1 files changed, 36 insertions, 17 deletions
diff --git a/scripts/build/buildWeb.mjs b/scripts/build/buildWeb.mjs
index a4ad87f..7508937 100755
--- a/scripts/build/buildWeb.mjs
+++ b/scripts/build/buildWeb.mjs
@@ -20,9 +20,9 @@
import esbuild from "esbuild";
import { zip } from "fflate";
-import { readFileSync, writeFileSync } from "fs";
+import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
import { readFile } from "fs/promises";
-import { join } from "path";
+import { join, resolve } from "path";
// wtf is this assert syntax
import PackageJSON from "../../package.json" assert { type: "json" };
@@ -72,20 +72,39 @@ await Promise.all(
]
);
-zip({
- dist: {
- "Vencord.js": readFileSync("dist/browser.js")
- },
- ...Object.fromEntries(await Promise.all(["modifyResponseHeaders.json", "content.js", "manifest.json"].map(async f => [
- f,
- await readFile(join("browser", f))
- ]))),
-}, {}, (err, data) => {
- if (err) {
- console.error(err);
- process.exitCode = 1;
+async function buildPluginZip(target, files, shouldZip) {
+ const entries = {
+ "dist/Vencord.js": readFileSync("dist/browser.js"),
+ ...Object.fromEntries(await Promise.all(files.map(async f => [
+ (f.startsWith("manifest") ? "manifest.json" : f),
+ await readFile(join("browser", f))
+ ]))),
+ };
+
+ if (shouldZip) {
+ zip(entries, {}, (err, data) => {
+ if (err) {
+ console.error(err);
+ process.exitCode = 1;
+ } else {
+ writeFileSync("dist/" + target, data);
+ console.info("Extension written to dist/" + target);
+ }
+ });
} else {
- writeFileSync("dist/extension.zip", data);
- console.info("Extension written to dist/extension.zip");
+ if (existsSync(target))
+ rmSync(target, { recursive: true });
+ for (const entry in entries) {
+ const destination = "dist/" + target + "/" + entry;
+ const parentDirectory = resolve(destination, "..");
+ mkdirSync(parentDirectory, { recursive: true });
+ writeFileSync(destination, entries[entry]);
+ }
+ console.info("Unpacked Extension written to dist/" + target);
}
-});
+}
+
+await buildPluginZip("extension-v3.zip", ["modifyResponseHeaders.json", "content.js", "manifestv3.json"], true);
+await buildPluginZip("extension-v2.zip", ["background.js", "content.js", "manifestv2.json"], true);
+await buildPluginZip("extension-v2-unpacked", ["background.js", "content.js", "manifestv2.json"], false);
+