Fix git commit not being available in dist build

This commit is contained in:
Pavel Djundik 2023-01-22 22:08:53 +02:00
parent c816e4053e
commit 2f04150461
2 changed files with 7 additions and 8 deletions

View File

@ -44,23 +44,23 @@ function getVersionNumber() {
return pkg.version; return pkg.version;
} }
let _fetchedGitCommit = false;
let _gitCommit: string | null = null; let _gitCommit: string | null = null;
function getGitCommit() { function getGitCommit() {
if (_gitCommit) { if (_fetchedGitCommit) {
return _gitCommit; return _gitCommit;
} }
if (!fs.existsSync(path.resolve(__dirname, "..", ".git"))) { _fetchedGitCommit = true;
_gitCommit = null;
return null;
}
// --git-dir ".git" makes git only check current directory for `.git`, and not travel upwards
// We set cwd to the location of `index.js` as soon as the process is started
try { try {
// eslint-disable-next-line @typescript-eslint/no-var-requires // eslint-disable-next-line @typescript-eslint/no-var-requires
_gitCommit = require("child_process") _gitCommit = require("child_process")
.execSync( .execSync(
"git rev-parse --short HEAD", // Returns hash of current commit 'git --git-dir ".git" rev-parse --short HEAD', // Returns hash of current commit
{stdio: ["ignore", "pipe", "ignore"]} {stdio: ["ignore", "pipe", "ignore"]}
) )
.toString() .toString()

View File

@ -9,7 +9,6 @@ import colors from "chalk";
import net from "net"; import net from "net";
import log from "./log"; import log from "./log";
import pkg from "../package.json";
import Client from "./client"; import Client from "./client";
import ClientManager from "./clientManager"; import ClientManager from "./clientManager";
import Uploader from "./plugins/uploader"; import Uploader from "./plugins/uploader";
@ -885,7 +884,7 @@ function getClientConfiguration(): ClientConfiguration {
config.isUpdateAvailable = changelog.isUpdateAvailable; config.isUpdateAvailable = changelog.isUpdateAvailable;
config.applicationServerKey = manager!.webPush.vapidKeys!.publicKey; config.applicationServerKey = manager!.webPush.vapidKeys!.publicKey;
config.version = pkg.version; config.version = Helper.getVersionNumber();
config.gitCommit = Helper.getGitCommit(); config.gitCommit = Helper.getGitCommit();
config.themes = themes.getAll(); config.themes = themes.getAll();
config.defaultTheme = Config.values.theme; config.defaultTheme = Config.values.theme;