aboutsummaryrefslogtreecommitdiff
path: root/scripts/build/buildWeb.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/build/buildWeb.mjs')
-rw-r--r--scripts/build/buildWeb.mjs61
1 files changed, 61 insertions, 0 deletions
diff --git a/scripts/build/buildWeb.mjs b/scripts/build/buildWeb.mjs
new file mode 100644
index 0000000..dd8cb5d
--- /dev/null
+++ b/scripts/build/buildWeb.mjs
@@ -0,0 +1,61 @@
+// TODO: Modularise the plugins since both build scripts use them
+
+import { createWriteStream, readFileSync } from "fs";
+import yazl from "yazl";
+import esbuild from "esbuild";
+// wtf is this assert syntax
+import PackageJSON from "../../package.json" assert { type: "json" };
+import { commonOpts, gitHashPlugin, globPlugins } from "./common.mjs";
+
+/**
+ * @type {esbuild.BuildOptions}
+ */
+const commonOptions = {
+ ...commonOpts,
+ entryPoints: ["browser/Vencord.ts"],
+ globalName: "Vencord",
+ format: "iife",
+ minify: true,
+ sourcemap: false,
+ external: ["plugins", "git-hash"],
+ plugins: [
+ globPlugins,
+ gitHashPlugin
+ ],
+ target: ["esnext"],
+ define: {
+ IS_WEB: "true"
+ }
+};
+
+await Promise.all(
+ [
+ esbuild.build({
+ ...commonOptions,
+ outfile: "dist/browser.js",
+ footer: { js: "//# sourceURL=VencordWeb" },
+ }),
+ esbuild.build({
+ ...commonOptions,
+ outfile: "dist/Vencord.user.js",
+ banner: {
+ js: readFileSync("browser/userscript.meta.js", "utf-8").replace("%version%", PackageJSON.version)
+ },
+ footer: {
+ // UserScripts get wrapped in an iife, so define Vencord prop on window that returns our local
+ js: "Object.defineProperty(window,'Vencord',{get:()=>Vencord});"
+ },
+ })
+ ]
+);
+
+const zip = new yazl.ZipFile();
+zip.outputStream.pipe(createWriteStream("dist/extension.zip")).on("close", () => {
+ console.info("Extension written to dist/extension.zip");
+});
+
+zip.addFile("dist/browser.js", "dist/Vencord.js");
+["background.js", "content.js", "manifest.json"].forEach(f => {
+ zip.addFile(`browser/${f}`, `${f}`);
+});
+zip.end();