Files
thelounge/server/version.ts
David Ashby 833a8bb362 include the version script in the NPM package (#5115)
Fix #5114.

Move version into the `./server` folder to be picked up by the build (and convert it to typescript).

Co-authored-by: Max Leiter <8675906+MaxLeiter@users.noreply.github.com>
2026-06-27 05:20:44 +00:00

48 lines
1016 B
TypeScript

import crypto from "crypto";
import {execSync} from "child_process";
import pkg from "../package.json";
let _gitCommit: string | null | undefined;
let _gitCommitFetched = false;
export function getGitCommit(): string | null {
if (_gitCommitFetched) {
return _gitCommit ?? null;
}
_gitCommitFetched = true;
try {
_gitCommit = execSync("git rev-parse --short HEAD", {
encoding: "utf-8",
timeout: 2000,
stdio: ["ignore", "pipe", "ignore"],
}).trim();
} catch {
_gitCommit = null;
}
return _gitCommit;
}
export function getVersion(): string {
const gitCommit = getGitCommit();
const version = `v${pkg.version}`;
return gitCommit ? `source (${gitCommit} / ${version})` : version;
}
export function getVersionNumber(): string {
return pkg.version;
}
let _cacheBust: string;
export function getVersionCacheBust(): string {
if (!_cacheBust) {
const hash = crypto.createHash("sha256").update(getVersion()).digest("hex");
_cacheBust = hash.substring(0, 10);
}
return _cacheBust;
}