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;
}
let _fetchedGitCommit = false;
let _gitCommit: string | null = null;
function getGitCommit() {
if (_gitCommit) {
if (_fetchedGitCommit) {
return _gitCommit;
}
if (!fs.existsSync(path.resolve(__dirname, "..", ".git"))) {
_gitCommit = null;
return null;
}
_fetchedGitCommit = true;
// --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 {
// eslint-disable-next-line @typescript-eslint/no-var-requires
_gitCommit = require("child_process")
.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"]}
)
.toString()

View file

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