Upload files to 'scripts/build'
This commit is contained in:
		
							parent
							
								
									e69bfc1ef5
								
							
						
					
					
						commit
						74c9bfb597
					
				
							
								
								
									
										98
									
								
								scripts/build/build.mts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										98
									
								
								scripts/build/build.mts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,98 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * SPDX-License-Identifier: GPL-3.0
 | 
				
			||||||
 | 
					 * Vesktop, a desktop app aiming to give you a snappier Discord Experience
 | 
				
			||||||
 | 
					 * Copyright (c) 2023 Vendicated and Vencord contributors
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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: !isDev, 
 | 
				
			||||||
 | 
					    bundle: true,
 | 
				
			||||||
 | 
					    sourcemap: "linked",
 | 
				
			||||||
 | 
					    logLevel: "info"
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const NodeCommonOpts: BuildOptions = {
 | 
				
			||||||
 | 
					    ...CommonOpts,
 | 
				
			||||||
 | 
					    format: "cjs",
 | 
				
			||||||
 | 
					    platform: "node",
 | 
				
			||||||
 | 
					    external: ["electron"],
 | 
				
			||||||
 | 
					    target: ["esnext"],
 | 
				
			||||||
 | 
					    define: {
 | 
				
			||||||
 | 
					        IS_DEV: JSON.stringify(isDev)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const contexts = [] as BuildContext[];
 | 
				
			||||||
 | 
					async function createContext(options: BuildOptions) {
 | 
				
			||||||
 | 
					    contexts.push(await context(options));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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({
 | 
				
			||||||
 | 
					        ...NodeCommonOpts,
 | 
				
			||||||
 | 
					        entryPoints: ["src/updater/preload.ts"],
 | 
				
			||||||
 | 
					        outfile: "dist/js/updaterPreload.js",
 | 
				
			||||||
 | 
					        footer: { js: "//# sourceURL=VCDUpdaterPreload" }
 | 
				
			||||||
 | 
					    }),
 | 
				
			||||||
 | 
					    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();
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										9
									
								
								scripts/build/injectReact.mjs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								scripts/build/injectReact.mjs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * SPDX-License-Identifier: GPL-3.0
 | 
				
			||||||
 | 
					 * Vesktop, a desktop app aiming to give you a snappier Discord Experience
 | 
				
			||||||
 | 
					 * Copyright (c) 2023 Vendicated and Vencord contributors
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const VencordFragment = /* #__PURE__*/ Symbol.for("react.fragment");
 | 
				
			||||||
 | 
					export let VencordCreateElement = (...args) =>
 | 
				
			||||||
 | 
					    (VencordCreateElement = Vencord.Webpack.Common.React.createElement)(...args);
 | 
				
			||||||
							
								
								
									
										74
									
								
								scripts/build/sandboxFix.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								scripts/build/sandboxFix.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,74 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * SPDX-License-Identifier: GPL-3.0
 | 
				
			||||||
 | 
					 * Vesktop, a desktop app aiming to give you a snappier Discord Experience
 | 
				
			||||||
 | 
					 * Copyright (c) 2023 Vendicated and Vencord contributors
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Based on https://github.com/gergof/electron-builder-sandbox-fix/blob/master/lib/index.js
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const fs = require("fs/promises");
 | 
				
			||||||
 | 
					const path = require("path");
 | 
				
			||||||
 | 
					let isApplied = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const hook = async () => {
 | 
				
			||||||
 | 
					    if (isApplied) return;
 | 
				
			||||||
 | 
					    isApplied = true;
 | 
				
			||||||
 | 
					    if (process.platform !== "linux") {
 | 
				
			||||||
 | 
					        // this fix is only required on linux
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    const AppImageTarget = require("app-builder-lib/out/targets/AppImageTarget");
 | 
				
			||||||
 | 
					    const oldBuildMethod = AppImageTarget.default.prototype.build;
 | 
				
			||||||
 | 
					    AppImageTarget.default.prototype.build = async function (...args) {
 | 
				
			||||||
 | 
					        console.log("Running AppImage builder hook", args);
 | 
				
			||||||
 | 
					        const oldPath = args[0];
 | 
				
			||||||
 | 
					        const newPath = oldPath + "-appimage-sandbox-fix";
 | 
				
			||||||
 | 
					        // just in case
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            await fs.rm(newPath, {
 | 
				
			||||||
 | 
					                recursive: true
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        } catch {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        console.log("Copying to apply appimage fix", oldPath, newPath);
 | 
				
			||||||
 | 
					        await fs.cp(oldPath, newPath, {
 | 
				
			||||||
 | 
					            recursive: true
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        args[0] = newPath;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const executable = path.join(newPath, this.packager.executableName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const loaderScript = `
 | 
				
			||||||
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					SCRIPT_DIR="$( cd "$( dirname "\${BASH_SOURCE[0]}" )" && pwd )"
 | 
				
			||||||
 | 
					IS_STEAMOS=0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [[ "$SteamOS" == "1" && "$SteamGamepadUI" == "1" ]]; then
 | 
				
			||||||
 | 
					    echo "Running Vesktop on SteamOS, disabling sandbox"
 | 
				
			||||||
 | 
					    IS_STEAMOS=1
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exec "$SCRIPT_DIR/${this.packager.executableName}.bin" "$([ "$IS_STEAMOS" == 1 ] && echo '--no-sandbox')" "$@"
 | 
				
			||||||
 | 
					                `.trim();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            await fs.rename(executable, executable + ".bin");
 | 
				
			||||||
 | 
					            await fs.writeFile(executable, loaderScript);
 | 
				
			||||||
 | 
					            await fs.chmod(executable, 0o755);
 | 
				
			||||||
 | 
					        } catch (e) {
 | 
				
			||||||
 | 
					            console.error("failed to create loder for sandbox fix: " + e.message);
 | 
				
			||||||
 | 
					            throw new Error("Failed to create loader for sandbox fix");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const ret = await oldBuildMethod.apply(this, args);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        await fs.rm(newPath, {
 | 
				
			||||||
 | 
					            recursive: true
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return ret;
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module.exports = hook;
 | 
				
			||||||
							
								
								
									
										38
									
								
								scripts/build/vencordDep.mts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								scripts/build/vencordDep.mts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,38 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * SPDX-License-Identifier: GPL-3.0
 | 
				
			||||||
 | 
					 * Vesktop, a desktop app aiming to give you a snappier Discord Experience
 | 
				
			||||||
 | 
					 * Copyright (c) 2023 Vendicated and Vencord contributors
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { globalExternalsWithRegExp } from "@fal-works/esbuild-plugin-global-externals";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const names = {
 | 
				
			||||||
 | 
					    webpack: "Vencord.Webpack",
 | 
				
			||||||
 | 
					    "webpack/common": "Vencord.Webpack.Common",
 | 
				
			||||||
 | 
					    utils: "Vencord.Util",
 | 
				
			||||||
 | 
					    api: "Vencord.Api",
 | 
				
			||||||
 | 
					    "api/settings": "Vencord",
 | 
				
			||||||
 | 
					    components: "Vencord.Components"
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default globalExternalsWithRegExp({
 | 
				
			||||||
 | 
					    getModuleInfo(modulePath) {
 | 
				
			||||||
 | 
					        const path = modulePath.replace("@vencord/types/", "");
 | 
				
			||||||
 | 
					        let varName = names[path];
 | 
				
			||||||
 | 
					        if (!varName) {
 | 
				
			||||||
 | 
					            const altMapping = names[path.split("/")[0]];
 | 
				
			||||||
 | 
					            if (!altMapping) throw new Error("Unknown module path: " + modulePath);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            varName =
 | 
				
			||||||
 | 
					                altMapping +
 | 
				
			||||||
 | 
					                "." +
 | 
				
			||||||
 | 
					                // @ts-ignore
 | 
				
			||||||
 | 
					                path.split("/")[1].replaceAll("/", ".");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            varName,
 | 
				
			||||||
 | 
					            type: "cjs"
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    modulePathFilter: /^@vencord\/types.+$/
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
		Reference in New Issue
	
	Block a user