SystemQueryy: Add version & commit properties

This commit is contained in:
Starbeamrainbowlabs 2022-02-24 01:27:41 +00:00
parent c9ac3ea108
commit 19ea1ff428
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 30 additions and 2 deletions

View file

@ -1,15 +1,18 @@
"use strict";
import fs from 'fs';
import path from 'path';
import { once, EventEmitter } from 'events';
import log from './io/NamespacedLog.mjs'; const l = log("systemquery");
import ItemQueue from './async/ItemQueue.mjs';
import current_git_commit from './io/current_git_commit.mjs';
import Agent from './agent/Agent.mjs';
import InfoBroker from './core/InfoBroker.mjs';
import HttpSubsystem from './agent/subsystems/http/HttpSubsystem.mjs';
import ItemQueue from './async/ItemQueue.mjs';
const __dirname = import.meta.url.slice(7, import.meta.url.lastIndexOf("/"));
class SystemQuery extends EventEmitter {
/**
@ -43,6 +46,11 @@ class SystemQuery extends EventEmitter {
this.config = config;
this.info = new InfoBroker();
this.pkg = null;
this.version = null;
this.commit = null;
this.agent = null;
this.http = new HttpSubsystem(this);
}
@ -51,6 +59,13 @@ class SystemQuery extends EventEmitter {
* @return {Promise} A Promise that resolves when initialisation is complete.
*/
async init() {
///
// 0: Preamble
///
this.pkg = JSON.parse(await fs.promises.readFile(path.join(__dirname, "../../package.json")));
this.version = this.pkg.version;
this.commit = await current_git_commit(path.join(__dirname, "../../.git"));
///
// 1: Create agent
///

View file

@ -0,0 +1,13 @@
"use strict";
import fs from 'fs';
import path from 'path';
export default async function(git_dir) {
const gitId = await fs.promises.readFile(path.join(git_dir, "HEAD"), 'utf8');
if (gitId.indexOf(':') === -1)
return gitId;
const refPath = path.join(git_dir, gitId.substring(5).trim());
return await fs.promises.readFile(refPath, 'utf8');
}