From 399305fd8a51de8f0e14d1898d9dd904c540f062 Mon Sep 17 00:00:00 2001 From: Ven Date: Thu, 26 Jan 2023 22:38:02 +0100 Subject: Automatic extension publishing (#453) --- scripts/build/buildWeb.mjs | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'scripts/build/buildWeb.mjs') diff --git a/scripts/build/buildWeb.mjs b/scripts/build/buildWeb.mjs index ceddbcb..dd7d32e 100644 --- a/scripts/build/buildWeb.mjs +++ b/scripts/build/buildWeb.mjs @@ -82,10 +82,19 @@ async function buildPluginZip(target, files, shouldZip) { const entries = { "dist/Vencord.js": await readFile("dist/browser.js"), "dist/Vencord.css": await readFile("dist/browser.css"), - ...Object.fromEntries(await Promise.all(files.map(async f => [ - (f.startsWith("manifest") ? "manifest.json" : f), - await readFile(join("browser", f)) - ]))), + ...Object.fromEntries(await Promise.all(files.map(async f => { + let content = await readFile(join("browser", f)); + if (f.startsWith("manifest")) { + const json = JSON.parse(content.toString("utf-8")); + json.version = PackageJSON.version; + content = new TextEncoder().encode(JSON.stringify(json)); + } + + return [ + f.startsWith("manifest") ? "manifest.json" : f, + content + ]; + }))), }; if (shouldZip) { @@ -115,20 +124,22 @@ async function buildPluginZip(target, files, shouldZip) { } } -const cssText = "`" + readFileSync("dist/Vencord.user.css", "utf-8").replaceAll("`", "\\`") + "`"; -const cssRuntime = ` +const appendCssRuntime = readFile("dist/Vencord.user.css", "utf-8").then(content => { + const cssRuntime = ` ;document.addEventListener("DOMContentLoaded", () => document.documentElement.appendChild( Object.assign(document.createElement("style"), { - textContent: ${cssText}, + textContent: \`${content.replaceAll("`", "\\`")}\`, id: "vencord-css-core" }) ), { once: true }); `; + return appendFile("dist/Vencord.user.js", cssRuntime); +}); + await Promise.all([ - appendFile("dist/Vencord.user.js", cssRuntime), - buildPluginZip("extension-v3.zip", ["modifyResponseHeaders.json", "content.js", "manifestv3.json"], true), - buildPluginZip("extension-v2.zip", ["background.js", "content.js", "manifestv2.json"], true), - buildPluginZip("extension-v2-unpacked", ["background.js", "content.js", "manifestv2.json"], false), + appendCssRuntime, + buildPluginZip("extension.zip", ["modifyResponseHeaders.json", "content.js", "manifest.json", "icon.png"], true), + buildPluginZip("extension-unpacked", ["modifyResponseHeaders.json", "content.js", "manifest.json", "icon.png"], false), ]); -- cgit