2020-05-27 10:18:04 +02:00
|
|
|
import * as fs from 'fs';
|
|
|
|
import * as os from 'os';
|
2020-10-13 10:27:52 +02:00
|
|
|
import logger from '../logger';
|
2020-05-27 10:18:04 +02:00
|
|
|
|
|
|
|
class BackendInfo {
|
|
|
|
gitCommitHash = '';
|
|
|
|
hostname = '';
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.setLatestCommitHash();
|
|
|
|
this.hostname = os.hostname();
|
|
|
|
}
|
|
|
|
|
|
|
|
public getBackendInfo() {
|
|
|
|
return {
|
|
|
|
'hostname': this.hostname,
|
|
|
|
'git-commit': this.gitCommitHash,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-10-13 12:48:43 +02:00
|
|
|
public getShortCommitHash() {
|
|
|
|
return this.gitCommitHash.slice(0, 7);
|
|
|
|
}
|
|
|
|
|
2020-05-27 10:18:04 +02:00
|
|
|
private setLatestCommitHash(): void {
|
|
|
|
try {
|
|
|
|
this.gitCommitHash = fs.readFileSync('../.git/refs/heads/master').toString().trim();
|
|
|
|
} catch (e) {
|
2020-10-13 10:27:52 +02:00
|
|
|
logger.err('Could not load git commit info, skipping.');
|
2020-05-27 10:18:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new BackendInfo();
|