SystemQueryy: Add version & commit properties
This commit is contained in:
parent
c9ac3ea108
commit
19ea1ff428
2 changed files with 30 additions and 2 deletions
|
@ -1,15 +1,18 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
import { once, EventEmitter } from 'events';
|
import { once, EventEmitter } from 'events';
|
||||||
|
|
||||||
import log from './io/NamespacedLog.mjs'; const l = log("systemquery");
|
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 Agent from './agent/Agent.mjs';
|
||||||
import InfoBroker from './core/InfoBroker.mjs';
|
import InfoBroker from './core/InfoBroker.mjs';
|
||||||
import HttpSubsystem from './agent/subsystems/http/HttpSubsystem.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 {
|
class SystemQuery extends EventEmitter {
|
||||||
/**
|
/**
|
||||||
|
@ -43,6 +46,11 @@ class SystemQuery extends EventEmitter {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.info = new InfoBroker();
|
this.info = new InfoBroker();
|
||||||
|
|
||||||
|
this.pkg = null;
|
||||||
|
this.version = null;
|
||||||
|
this.commit = null;
|
||||||
|
|
||||||
|
this.agent = null;
|
||||||
this.http = new HttpSubsystem(this);
|
this.http = new HttpSubsystem(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +59,13 @@ class SystemQuery extends EventEmitter {
|
||||||
* @return {Promise} A Promise that resolves when initialisation is complete.
|
* @return {Promise} A Promise that resolves when initialisation is complete.
|
||||||
*/
|
*/
|
||||||
async init() {
|
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
|
// 1: Create agent
|
||||||
///
|
///
|
||||||
|
|
13
src/lib/io/current_git_commit.mjs
Normal file
13
src/lib/io/current_git_commit.mjs
Normal 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');
|
||||||
|
}
|
Loading…
Reference in a new issue