build: allow overriding git details & disabling updating (#1677)
Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
parent
f628aa7a70
commit
714d87241c
@ -19,13 +19,14 @@
|
|||||||
|
|
||||||
import esbuild from "esbuild";
|
import esbuild from "esbuild";
|
||||||
|
|
||||||
import { commonOpts, globPlugins, isStandalone, VERSION, watch } from "./common.mjs";
|
import { BUILD_TIMESTAMP, commonOpts, globPlugins, isStandalone, updaterDisabled, VERSION, watch } from "./common.mjs";
|
||||||
|
|
||||||
const defines = {
|
const defines = {
|
||||||
IS_STANDALONE: isStandalone,
|
IS_STANDALONE: isStandalone,
|
||||||
IS_DEV: JSON.stringify(watch),
|
IS_DEV: JSON.stringify(watch),
|
||||||
|
IS_UPDATER_DISABLED: updaterDisabled,
|
||||||
VERSION: JSON.stringify(VERSION),
|
VERSION: JSON.stringify(VERSION),
|
||||||
BUILD_TIMESTAMP: Date.now(),
|
BUILD_TIMESTAMP,
|
||||||
};
|
};
|
||||||
if (defines.IS_STANDALONE === "false")
|
if (defines.IS_STANDALONE === "false")
|
||||||
// If this is a local build (not standalone), optimise
|
// If this is a local build (not standalone), optimise
|
||||||
|
@ -24,7 +24,7 @@ import { readFileSync } from "fs";
|
|||||||
import { appendFile, mkdir, readFile, rm, writeFile } from "fs/promises";
|
import { appendFile, mkdir, readFile, rm, writeFile } from "fs/promises";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
|
|
||||||
import { commonOpts, globPlugins, VERSION, watch } from "./common.mjs";
|
import { BUILD_TIMESTAMP, commonOpts, globPlugins, VERSION, watch } from "./common.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {esbuild.BuildOptions}
|
* @type {esbuild.BuildOptions}
|
||||||
@ -46,8 +46,9 @@ const commonOptions = {
|
|||||||
IS_DEV: JSON.stringify(watch),
|
IS_DEV: JSON.stringify(watch),
|
||||||
IS_DISCORD_DESKTOP: "false",
|
IS_DISCORD_DESKTOP: "false",
|
||||||
IS_VESKTOP: "false",
|
IS_VESKTOP: "false",
|
||||||
|
IS_UPDATER_DISABLED: "true",
|
||||||
VERSION: JSON.stringify(VERSION),
|
VERSION: JSON.stringify(VERSION),
|
||||||
BUILD_TIMESTAMP: Date.now(),
|
BUILD_TIMESTAMP,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,15 +30,18 @@ import PackageJSON from "../../package.json" assert { type: "json" };
|
|||||||
import { getPluginTarget } from "../utils.mjs";
|
import { getPluginTarget } from "../utils.mjs";
|
||||||
|
|
||||||
export const VERSION = PackageJSON.version;
|
export const VERSION = PackageJSON.version;
|
||||||
export const BUILD_TIMESTAMP = Date.now();
|
// https://reproducible-builds.org/docs/source-date-epoch/
|
||||||
|
export const BUILD_TIMESTAMP = Number(process.env.SOURCE_DATE_EPOCH) || Date.now();
|
||||||
export const watch = process.argv.includes("--watch");
|
export const watch = process.argv.includes("--watch");
|
||||||
export const isStandalone = JSON.stringify(process.argv.includes("--standalone"));
|
export const isStandalone = JSON.stringify(process.argv.includes("--standalone"));
|
||||||
export const gitHash = execSync("git rev-parse --short HEAD", { encoding: "utf-8" }).trim();
|
export const updaterDisabled = JSON.stringify(process.argv.includes("--disable-updater"));
|
||||||
|
export const gitHash = process.env.VENCORD_HASH || execSync("git rev-parse --short HEAD", { encoding: "utf-8" }).trim();
|
||||||
export const banner = {
|
export const banner = {
|
||||||
js: `
|
js: `
|
||||||
// Vencord ${gitHash}
|
// Vencord ${gitHash}
|
||||||
// Standalone: ${isStandalone}
|
// Standalone: ${isStandalone}
|
||||||
// Platform: ${isStandalone === "false" ? process.platform : "Universal"}
|
// Platform: ${isStandalone === "false" ? process.platform : "Universal"}
|
||||||
|
// Updater disabled: ${updaterDisabled}
|
||||||
`.trim()
|
`.trim()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -133,11 +136,14 @@ export const gitRemotePlugin = {
|
|||||||
namespace: "git-remote", path: args.path
|
namespace: "git-remote", path: args.path
|
||||||
}));
|
}));
|
||||||
build.onLoad({ filter, namespace: "git-remote" }, async () => {
|
build.onLoad({ filter, namespace: "git-remote" }, async () => {
|
||||||
|
let remote = process.env.VENCORD_REMOTE;
|
||||||
|
if (!remote) {
|
||||||
const res = await promisify(exec)("git remote get-url origin", { encoding: "utf-8" });
|
const res = await promisify(exec)("git remote get-url origin", { encoding: "utf-8" });
|
||||||
const remote = res.stdout.trim()
|
remote = res.stdout.trim()
|
||||||
.replace("https://github.com/", "")
|
.replace("https://github.com/", "")
|
||||||
.replace("git@github.com:", "")
|
.replace("git@github.com:", "")
|
||||||
.replace(/.git$/, "");
|
.replace(/.git$/, "");
|
||||||
|
}
|
||||||
|
|
||||||
return { contents: `export default "${remote}"` };
|
return { contents: `export default "${remote}"` };
|
||||||
});
|
});
|
||||||
|
@ -249,4 +249,4 @@ function Updater() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default IS_WEB ? null : wrapTab(Updater, "Updater");
|
export default IS_UPDATER_DISABLED ? null : wrapTab(Updater, "Updater");
|
||||||
|
1
src/globals.d.ts
vendored
1
src/globals.d.ts
vendored
@ -35,6 +35,7 @@ declare global {
|
|||||||
export var IS_WEB: boolean;
|
export var IS_WEB: boolean;
|
||||||
export var IS_DEV: boolean;
|
export var IS_DEV: boolean;
|
||||||
export var IS_STANDALONE: boolean;
|
export var IS_STANDALONE: boolean;
|
||||||
|
export var IS_UPDATER_DISABLED: boolean;
|
||||||
export var IS_DISCORD_DESKTOP: boolean;
|
export var IS_DISCORD_DESKTOP: boolean;
|
||||||
export var IS_VESKTOP: boolean;
|
export var IS_VESKTOP: boolean;
|
||||||
export var VERSION: string;
|
export var VERSION: string;
|
||||||
|
@ -16,4 +16,5 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import(IS_STANDALONE ? "./http" : "./git");
|
if (!IS_UPDATER_DISABLED)
|
||||||
|
import(IS_STANDALONE ? "./http" : "./git");
|
||||||
|
@ -103,7 +103,7 @@ export default definePlugin({
|
|||||||
element: require("@components/VencordSettings/ThemesTab").default,
|
element: require("@components/VencordSettings/ThemesTab").default,
|
||||||
className: "vc-themes"
|
className: "vc-themes"
|
||||||
},
|
},
|
||||||
!IS_WEB && {
|
!IS_UPDATER_DISABLED && {
|
||||||
section: "VencordUpdater",
|
section: "VencordUpdater",
|
||||||
label: "Updater",
|
label: "Updater",
|
||||||
element: require("@components/VencordSettings/UpdaterTab").default,
|
element: require("@components/VencordSettings/UpdaterTab").default,
|
||||||
|
@ -63,7 +63,7 @@ export async function update() {
|
|||||||
export const getRepo = () => Unwrap(VencordNative.updater.getRepo());
|
export const getRepo = () => Unwrap(VencordNative.updater.getRepo());
|
||||||
|
|
||||||
export async function maybePromptToUpdate(confirmMessage: string, checkForDev = false) {
|
export async function maybePromptToUpdate(confirmMessage: string, checkForDev = false) {
|
||||||
if (IS_WEB) return;
|
if (IS_WEB || IS_UPDATER_DISABLED) return;
|
||||||
if (checkForDev && IS_DEV) return;
|
if (checkForDev && IS_DEV) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user