diff options
author | nea <romangraef@gmail.com> | 2022-12-01 07:48:18 +0100 |
---|---|---|
committer | nea <romangraef@gmail.com> | 2022-12-01 07:48:18 +0100 |
commit | ed2b72992221fe87fb2b18819975130d0e7911a4 (patch) | |
tree | 74905c5eb2eea47695fbafbdbf316181095e1210 /scripts | |
parent | 05fe47dd2050fb5b0e5f90598526adf70b4e0ed1 (diff) | |
download | Vencord-ed2b72992221fe87fb2b18819975130d0e7911a4.tar.gz Vencord-ed2b72992221fe87fb2b18819975130d0e7911a4.tar.bz2 Vencord-ed2b72992221fe87fb2b18819975130d0e7911a4.zip |
Manifest V2: Add signing support to manifest V2 extensions
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/build/buildWeb.mjs | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/scripts/build/buildWeb.mjs b/scripts/build/buildWeb.mjs index 74f0857..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,26 +72,39 @@ await Promise.all( ] ); -async function buildPluginZip(target, files) { - zip({ - dist: { - "Vencord.js": readFileSync("dist/browser.js") - }, +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)) ]))), - }, {}, (err, data) => { - if (err) { - console.error(err); - process.exitCode = 1; - } else { - writeFileSync("dist/" + target, data); - console.info("Extension written to dist/" + target); + }; + + 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 { + 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"]); -await buildPluginZip("extension-v2.xpi", ["background.js", "content.js", "manifestv2.json"]); +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); |