From ffb7047021c1a30edc45705c606ca77f88d72705 Mon Sep 17 00:00:00 2001 From: Admin Date: Fri, 20 Dec 2024 09:43:40 -0800 Subject: [PATCH] a --- scripts/build/build.mts | 105 +++++++++++++++++++++++++--------------- 1 file changed, 65 insertions(+), 40 deletions(-) diff --git a/scripts/build/build.mts b/scripts/build/build.mts index 9a9d945..4e9de92 100644 --- a/scripts/build/build.mts +++ b/scripts/build/build.mts @@ -6,14 +6,17 @@ * Copyright (c) 2023 Vendicated and Vencord contributors */ -import { BuildOptions, build } from "esbuild"; +import { BuildContext, BuildOptions, context } from "esbuild"; +import { copyFile } from "fs/promises"; + +import vencordDep from "./vencordDep.mjs"; const isDev = process.argv.includes("--dev"); const CommonOpts: BuildOptions = { - minify: true, + minify: !isDev, bundle: true, - sourcemap: "inline", + sourcemap: "linked", logLevel: "info" }; @@ -28,42 +31,64 @@ const NodeCommonOpts: BuildOptions = { } }; -async function buildUnpacked() { - await Promise.all([ - build({ - ...NodeCommonOpts, - entryPoints: ["src/main/index.ts"], - outfile: "dist/js/main.js", - footer: { js: "//# sourceURL=VCDMain" } - }), - build({ - ...NodeCommonOpts, - entryPoints: ["src/preload/index.ts"], - outfile: "dist/js/preload.js", - footer: { js: "//# sourceURL=VCDPreload" } - }), - build({ - ...NodeCommonOpts, - entryPoints: ["src/updater/preload.ts"], - outfile: "dist/js/updaterPreload.js", - footer: { js: "//# sourceURL=VCDUpdaterPreload" } - }), - build({ - ...CommonOpts, - globalName: "Vesktop", - entryPoints: ["src/renderer/index.ts"], - outfile: "dist/js/renderer.js", - format: "iife", - inject: ["./scripts/build/injectReact.mjs"], - jsxFactory: "VencordCreateElement", - jsxFragment: "VencordFragment", - external: ["@vencord/types/*"], - footer: { js: "//# sourceURL=VCDRenderer" } - }) - ]); +const contexts = [] as BuildContext[]; +async function createContext(options: BuildOptions) { + contexts.push(await context(options)); } -buildUnpacked().catch(err => { - console.error("Build failed:", err); - process.exit(1); -}); +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", + "./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(), + createContext({ + ...NodeCommonOpts, + entryPoints: ["src/main/index.ts"], + outfile: "dist/js/main.js", + footer: { js: "//# sourceURL=VCDMain" } + }), + createContext({ + ...NodeCommonOpts, + entryPoints: ["src/preload/index.ts"], + outfile: "dist/js/preload.js", + footer: { js: "//# sourceURL=VCDPreload" } + }), + createContext({ + ...CommonOpts, + globalName: "Vesktop", + entryPoints: ["src/renderer/index.ts"], + outfile: "dist/js/renderer.js", + format: "iife", + inject: ["./scripts/build/injectReact.mjs"], + jsxFactory: "VencordCreateElement", + jsxFragment: "VencordFragment", + external: ["@vencord/types/*"], + plugins: [vencordDep], + footer: { js: "//# sourceURL=VCDRenderer" } + }) +]); + +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(); + }) + ); +} \ No newline at end of file