From d26196d6c52c092a8e2ef302a2aeec538ff2fe23 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Fri, 14 Oct 2022 00:12:30 +0200 Subject: [PATCH] Add a UserScript build --- .github/workflows/build.yml | 15 ++++++------- browser/userscript.meta.js | 23 ++++++++++++++++++++ buildWeb.mjs | 42 +++++++++++++++++++++++++++++-------- 3 files changed, 64 insertions(+), 16 deletions(-) create mode 100644 browser/userscript.meta.js diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1639c633..82b17c72 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: branches: - main env: - FORCE_COLOR: true + FORCE_COLOR: true jobs: Build: @@ -26,22 +26,22 @@ jobs: - name: Build web run: pnpm buildWeb - + - name: Build run: pnpm build - + - name: Get some values needed for the release id: vars shell: bash run: | - echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" + echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" - uses: dev-drprasad/delete-tag-and-release@085c6969f18bad0de1b9f3fe6692a3cd01f64fe5 # v0.2.0 with: - delete_release: true - tag_name: devbuild + delete_release: true + tag_name: devbuild env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Create the release uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v1 @@ -53,6 +53,7 @@ jobs: draft: false prerelease: false files: | + dist/Vencord.user.js dist/browser.js dist/extension.zip dist/renderer.js diff --git a/browser/userscript.meta.js b/browser/userscript.meta.js new file mode 100644 index 00000000..e2a3de52 --- /dev/null +++ b/browser/userscript.meta.js @@ -0,0 +1,23 @@ +// ==UserScript== +// @name Vencord +// @description A Discord client mod - Web version +// @version %version% +// @author Vendicated (https://github.com/Vendicated) +// @namespace https://github.com/Vendicated/Vencord +// @supportURL https://github.com/Vendicated/Vencord +// @license GPL-3.0 +// @match *://*.discord.com/* +// @grant none +// @run-at document-start +// @compatible chrome Chrome + Tampermonkey or Violentmonkey +// @compatible firefox Firefox Tampermonkey +// @compatible opera Opera + Tampermonkey or Violentmonkey +// @compatible edge Edge + Tampermonkey or Violentmonkey +// @compatible safari Safari + Tampermonkey or Violentmonkey +// ==/UserScript== + +// this UserScript DOES NOT work on Firefox with Violentmonkey or Greasemonkey due to a bug that makes it impossible +// to overwrite stuff on the window on sites that use CSP. Use Tampermonkey or use a chromium based browser +// https://github.com/violentmonkey/violentmonkey/issues/997 + +// this is a compiled and minified version of Vencord. For the source code, visit the GitHub repo diff --git a/buildWeb.mjs b/buildWeb.mjs index 9031d149..afb8b339 100644 --- a/buildWeb.mjs +++ b/buildWeb.mjs @@ -1,9 +1,11 @@ // TODO: Modularise these plugins since both build scripts use them import { execSync } from "child_process"; -import { createWriteStream, readdirSync } from "fs"; +import { createWriteStream, readdirSync, readFileSync } from "fs"; import yazl from "yazl"; import esbuild from "esbuild"; +// wtf is this assert syntax +import PackageJSON from "./package.json" assert { type: "json" }; /** * @type {esbuild.Plugin} @@ -56,23 +58,45 @@ const gitHashPlugin = { } }; -await esbuild.build({ +/** + * @type {esbuild.BuildOptions} + */ +const commonOptions = { logLevel: "info", entryPoints: ["browser/Vencord.ts"], - outfile: "dist/browser.js", + globalName: "Vencord", format: "iife", bundle: true, - globalName: "Vencord", - target: ["esnext"], - footer: { js: "//# sourceURL=VencordWeb" }, + minify: true, + sourcemap: false, external: ["plugins", "git-hash"], plugins: [ globPlugins, gitHashPlugin ], - sourcemap: false, - minify: true, -}); + target: ["esnext"], +}; + +await Promise.all( + [ + esbuild.build({ + ...commonOptions, + outfile: "dist/browser.js", + footer: { js: "//# sourceURL=VencordWeb" }, + }), + esbuild.build({ + ...commonOptions, + outfile: "dist/Vencord.user.js", + banner: { + js: readFileSync("browser/userscript.meta.js", "utf-8").replace("%version%", PackageJSON.version) + }, + footer: { + // UserScripts get wrapped in an iife, so define Vencord prop on window that returns our local + js: "Object.defineProperty(window,'Vencord',{get:()=>Vencord});" + }, + }) + ] +); const zip = new yazl.ZipFile(); zip.outputStream.pipe(createWriteStream("dist/extension.zip")).on("close", () => {