project-client/scripts/build/build.mts

93 lines
2.5 KiB
TypeScript
Raw Normal View History

/*
* 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
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
2023-03-29 23:02:30 +00:00
import { BuildContext, BuildOptions, context } from "esbuild";
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";
const isDev = process.argv.includes("--dev");
const CommonOpts: BuildOptions = {
minify: !isDev,
2023-03-29 23:02:30 +00:00
bundle: true,
sourcemap: "linked",
logLevel: "info"
};
const NodeCommonOpts: BuildOptions = {
...CommonOpts,
format: "cjs",
platform: "node",
external: ["electron"],
target: ["esnext"],
define: {
IS_DEV: JSON.stringify(isDev)
}
};
2023-03-29 23:02:30 +00:00
const contexts = [] as BuildContext[];
async function createContext(options: BuildOptions) {
contexts.push(await context(options));
}
2023-10-26 22:42:50 +00:00
async function copyVenmic() {
if (process.platform !== "linux") return;
return Promise.all([
copyFile(
"./node_modules/@vencord/venmic/prebuilds/venmic-addon-linux-x64/node-napi-v7.node",
2023-10-26 22:42:50 +00:00
"./static/dist/venmic-x64.node"
),
copyFile(
"./node_modules/@vencord/venmic/prebuilds/venmic-addon-linux-arm64/node-napi-v7.node",
"./static/dist/venmic-arm64.node"
)
]).catch(() => console.warn("Failed to copy venmic. Building without venmic support"));
}
await Promise.all([
copyVenmic(),
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" }
}),
createContext({
...CommonOpts,
2023-07-13 17:03:13 +00:00
globalName: "Vesktop",
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",
2023-04-19 20:47:47 +00:00
external: ["@vencord/types/*"],
plugins: [vencordDep],
2023-10-21 20:25:16 +00:00
footer: { js: "//# 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 {
await Promise.all(
contexts.map(async ctx => {
await ctx.rebuild();
await ctx.dispose();
})
);
2023-03-29 23:02:30 +00:00
}