aboutsummaryrefslogtreecommitdiff
path: root/scripts/build
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2022-10-22 04:41:33 +0200
committerVendicated <vendicated@riseup.net>2022-10-22 04:42:54 +0200
commit44f6f71c3efd2e4e0f9dbd97ab4680ec76536052 (patch)
treecd2ad847833ff428e009ca55b50eabd57031443d /scripts/build
parent23d4cae1230bd60da2f0497ecac9d4a32a326f5b (diff)
downloadVencord-44f6f71c3efd2e4e0f9dbd97ab4680ec76536052.tar.gz
Vencord-44f6f71c3efd2e4e0f9dbd97ab4680ec76536052.tar.bz2
Vencord-44f6f71c3efd2e4e0f9dbd97ab4680ec76536052.zip
Monaco for Discord Desktop
Diffstat (limited to 'scripts/build')
-rwxr-xr-xscripts/build/build.mjs9
-rwxr-xr-xscripts/build/buildWeb.mjs5
-rw-r--r--scripts/build/common.mjs51
3 files changed, 46 insertions, 19 deletions
diff --git a/scripts/build/build.mjs b/scripts/build/build.mjs
index f6304b1..1986369 100755
--- a/scripts/build/build.mjs
+++ b/scripts/build/build.mjs
@@ -18,7 +18,7 @@
*/
import esbuild from "esbuild";
-import { commonOpts, gitHashPlugin, globPlugins, makeAllPackagesExternalPlugin } from "./common.mjs";
+import { commonOpts, fileIncludePlugin, gitHashPlugin, globPlugins, makeAllPackagesExternalPlugin } from "./common.mjs";
/**
* @type {esbuild.BuildOptions}
@@ -30,7 +30,7 @@ const nodeCommonOpts = {
target: ["esnext"],
minify: true,
sourcemap: "linked",
- plugins: [makeAllPackagesExternalPlugin],
+ plugins: [...commonOpts.plugins, makeAllPackagesExternalPlugin],
};
await Promise.all([
@@ -55,7 +55,8 @@ await Promise.all([
external: ["plugins", "git-hash"],
plugins: [
globPlugins,
- gitHashPlugin
+ gitHashPlugin,
+ fileIncludePlugin
],
define: {
IS_WEB: "false"
@@ -65,6 +66,6 @@ await Promise.all([
console.error("Build failed");
console.error(err.message);
// make ci fail
- if (!watch)
+ if (!commonOpts.watch)
process.exitCode = 1;
});
diff --git a/scripts/build/buildWeb.mjs b/scripts/build/buildWeb.mjs
index 8abac2c..286aad3 100755
--- a/scripts/build/buildWeb.mjs
+++ b/scripts/build/buildWeb.mjs
@@ -23,7 +23,7 @@ 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";
+import { commonOpts, fileIncludePlugin, gitHashPlugin, globPlugins } from "./common.mjs";
/**
* @type {esbuild.BuildOptions}
@@ -36,7 +36,8 @@ const commonOptions = {
external: ["plugins", "git-hash"],
plugins: [
globPlugins,
- gitHashPlugin
+ gitHashPlugin,
+ fileIncludePlugin
],
target: ["esnext"],
define: {
diff --git a/scripts/build/common.mjs b/scripts/build/common.mjs
index 6143fb2..c3afc7f 100644
--- a/scripts/build/common.mjs
+++ b/scripts/build/common.mjs
@@ -19,22 +19,11 @@
import { execSync } from "child_process";
import esbuild from "esbuild";
import { existsSync } from "fs";
-import { readdir } from "fs/promises";
+import { readdir, readFile } from "fs/promises";
+import { join } from "path";
const watch = process.argv.includes("--watch");
-/**
- * @type {esbuild.BuildOptions}
- */
-export const commonOpts = {
- logLevel: "info",
- bundle: true,
- watch,
- minify: !watch,
- sourcemap: watch ? "inline" : "",
- legalComments: "linked"
-};
-
// https://github.com/evanw/esbuild/issues/619#issuecomment-751995294
/**
* @type {esbuild.Plugin}
@@ -103,3 +92,39 @@ export const gitHashPlugin = {
}));
}
};
+
+/**
+ * @type {esbuild.Plugin}
+ */
+export const fileIncludePlugin = {
+ name: "file-include-plugin",
+ setup: build => {
+ const filter = /^@fileContent\/.+$/;
+ build.onResolve({ filter }, args => ({
+ namespace: "include-file",
+ path: args.path,
+ pluginData: {
+ path: join(args.resolveDir, args.path.slice("include-file/".length))
+ }
+ }));
+ build.onLoad({ filter, namespace: "include-file" }, async ({ pluginData: { path } }) => {
+ const [name, format] = path.split(";");
+ return {
+ contents: `export default ${JSON.stringify(await readFile(name, format ?? "utf-8"))}`
+ };
+ });
+ }
+};
+
+/**
+ * @type {esbuild.BuildOptions}
+ */
+export const commonOpts = {
+ logLevel: "info",
+ bundle: true,
+ watch,
+ minify: !watch,
+ sourcemap: watch ? "inline" : "",
+ legalComments: "linked",
+ plugins: [fileIncludePlugin]
+};