2023-04-10 20:05:21 +00:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0
|
2023-07-13 17:03:13 +00:00
|
|
|
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
|
2023-04-10 20:05:21 +00:00
|
|
|
* Copyright (c) 2023 Vendicated and Vencord contributors
|
|
|
|
*/
|
|
|
|
|
2023-03-29 23:02:30 +00:00
|
|
|
import { BuildContext, BuildOptions, context } from "esbuild";
|
2023-10-21 20:15:55 +00:00
|
|
|
import { copyFile } from "fs/promises";
|
2023-03-29 23:02:30 +00:00
|
|
|
|
2023-04-19 20:47:47 +00:00
|
|
|
import vencordDep from "./vencordDep.mjs";
|
|
|
|
|
2023-04-09 00:26:31 +00:00
|
|
|
const isDev = process.argv.includes("--dev");
|
|
|
|
|
2023-04-04 02:40:03 +00:00
|
|
|
const CommonOpts: BuildOptions = {
|
2023-04-09 00:26:31 +00:00
|
|
|
minify: !isDev,
|
2023-03-29 23:02:30 +00:00
|
|
|
bundle: true,
|
|
|
|
sourcemap: "linked",
|
|
|
|
logLevel: "info"
|
|
|
|
};
|
|
|
|
|
2023-04-04 02:40:03 +00:00
|
|
|
const NodeCommonOpts: BuildOptions = {
|
|
|
|
...CommonOpts,
|
|
|
|
format: "cjs",
|
|
|
|
platform: "node",
|
|
|
|
external: ["electron"],
|
|
|
|
target: ["esnext"],
|
2023-04-09 00:26:31 +00:00
|
|
|
define: {
|
|
|
|
IS_DEV: JSON.stringify(isDev)
|
|
|
|
}
|
2023-04-04 02:40:03 +00:00
|
|
|
};
|
|
|
|
|
2023-03-29 23:02:30 +00:00
|
|
|
const contexts = [] as BuildContext[];
|
|
|
|
async function createContext(options: BuildOptions) {
|
|
|
|
contexts.push(await context(options));
|
|
|
|
}
|
|
|
|
|
|
|
|
await Promise.all([
|
2023-10-21 20:15:55 +00:00
|
|
|
process.platform === "linux" &&
|
|
|
|
copyFile(
|
|
|
|
"./node_modules/@vencord/venmic/prebuilds/venmic-addon-linux-x64/node-napi-v7.node",
|
|
|
|
"./static/dist/venmic.node"
|
|
|
|
).catch(() => console.warn("Failed to copy venmic. Building without venmic support")),
|
2023-03-29 23:02:30 +00:00
|
|
|
createContext({
|
|
|
|
...NodeCommonOpts,
|
|
|
|
entryPoints: ["src/main/index.ts"],
|
2023-04-19 20:47:47 +00:00
|
|
|
outfile: "dist/js/main.js",
|
|
|
|
footer: { js: "//# sourceURL=VCDMain" }
|
2023-03-29 23:02:30 +00:00
|
|
|
}),
|
|
|
|
createContext({
|
|
|
|
...NodeCommonOpts,
|
|
|
|
entryPoints: ["src/preload/index.ts"],
|
2023-04-19 20:47:47 +00:00
|
|
|
outfile: "dist/js/preload.js",
|
|
|
|
footer: { js: "//# sourceURL=VCDPreload" }
|
2023-04-04 02:40:03 +00:00
|
|
|
}),
|
2023-04-10 20:53:44 +00:00
|
|
|
createContext({
|
|
|
|
...NodeCommonOpts,
|
|
|
|
entryPoints: ["src/updater/preload.ts"],
|
2023-04-19 20:47:47 +00:00
|
|
|
outfile: "dist/js/updaterPreload.js",
|
|
|
|
footer: { js: "//# sourceURL=VCDUpdaterPreload" }
|
2023-04-10 20:53:44 +00:00
|
|
|
}),
|
2023-04-04 02:40:03 +00:00
|
|
|
createContext({
|
|
|
|
...CommonOpts,
|
2023-07-13 17:03:13 +00:00
|
|
|
globalName: "Vesktop",
|
2023-04-04 02:40:03 +00:00
|
|
|
entryPoints: ["src/renderer/index.ts"],
|
|
|
|
outfile: "dist/js/renderer.js",
|
|
|
|
format: "iife",
|
2023-04-08 22:49:47 +00:00
|
|
|
inject: ["./scripts/build/injectReact.mjs"],
|
|
|
|
jsxFactory: "VencordCreateElement",
|
|
|
|
jsxFragment: "VencordFragment",
|
|
|
|
// Work around https://github.com/evanw/esbuild/issues/2460
|
2023-04-19 20:47:47 +00:00
|
|
|
tsconfig: "./scripts/build/tsconfig.esbuild.json",
|
|
|
|
external: ["@vencord/types/*"],
|
|
|
|
plugins: [vencordDep],
|
2023-07-13 17:03:13 +00:00
|
|
|
// TODO: remove legacy name once main Vencord codebase has migrated and some time has passed.
|
|
|
|
// this 0 is very important. we run this script via webFrame.executeJavaScript and the last
|
|
|
|
// expression will be the return value. Without the 0, the return value would be Vesktop which
|
|
|
|
// leads to "An object could not be cloned"
|
|
|
|
footer: { js: ";window.VencordDesktop=Vesktop;0 \n//# sourceURL=VCDRenderer" }
|
2023-03-29 23:02:30 +00:00
|
|
|
})
|
|
|
|
]);
|
|
|
|
|
|
|
|
const watch = process.argv.includes("--watch");
|
|
|
|
|
|
|
|
if (watch) {
|
|
|
|
await Promise.all(contexts.map(ctx => ctx.watch()));
|
|
|
|
} else {
|
2023-04-10 20:05:21 +00:00
|
|
|
await Promise.all(
|
|
|
|
contexts.map(async ctx => {
|
|
|
|
await ctx.rebuild();
|
|
|
|
await ctx.dispose();
|
|
|
|
})
|
|
|
|
);
|
2023-03-29 23:02:30 +00:00
|
|
|
}
|