Read version info from config instead of hard-coded string
This commit is contained in:
parent
d133efe228
commit
a3244cd6fc
2 changed files with 51 additions and 21 deletions
|
|
@ -2,27 +2,52 @@ const fs = require('fs');
|
||||||
|
|
||||||
class Configuration {
|
class Configuration {
|
||||||
static _options = null;
|
static _options = null;
|
||||||
|
static _addonInfo = null;
|
||||||
|
|
||||||
static getOptions() {
|
static getOptions() {
|
||||||
if (!Configuration._options) {
|
if (!Configuration._options) {
|
||||||
const rawData = fs.readFileSync('/data/options.json');
|
Configuration._hydrateCache();
|
||||||
const config = JSON.parse(rawData);
|
|
||||||
|
|
||||||
const defaultRawData = fs.readFileSync('/plejd/config.json');
|
|
||||||
const defaultConfig = JSON.parse(defaultRawData).options;
|
|
||||||
|
|
||||||
Configuration._options = { ...defaultConfig, ...config };
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log('Config:', {
|
|
||||||
...Configuration._options,
|
|
||||||
username: '---scrubbed---',
|
|
||||||
password: '---scrubbed---',
|
|
||||||
mqttPassword: '---scrubbed---',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return Configuration._options;
|
return Configuration._options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getAddonInfo() {
|
||||||
|
if (!Configuration._addonInfo) {
|
||||||
|
Configuration._hydrateCache();
|
||||||
|
}
|
||||||
|
return Configuration._addonInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
static _hydrateCache() {
|
||||||
|
const rawData = fs.readFileSync('/data/options.json');
|
||||||
|
const config = JSON.parse(rawData);
|
||||||
|
|
||||||
|
const defaultRawData = fs.readFileSync('/plejd/config.json');
|
||||||
|
const defaultConfig = JSON.parse(defaultRawData);
|
||||||
|
|
||||||
|
Configuration._options = { ...defaultConfig.options, ...config };
|
||||||
|
Configuration._addonInfo = {
|
||||||
|
name: defaultConfig.name,
|
||||||
|
version: defaultConfig.version,
|
||||||
|
slug: defaultConfig.slug,
|
||||||
|
description: defaultConfig.description,
|
||||||
|
url: defaultConfig.url,
|
||||||
|
arch: defaultConfig.arch,
|
||||||
|
startup: defaultConfig.startup,
|
||||||
|
boot: defaultConfig.boot,
|
||||||
|
host_network: defaultConfig.host_network,
|
||||||
|
host_dbus: defaultConfig.host_dbus,
|
||||||
|
apparmor: defaultConfig.apparmor,
|
||||||
|
};
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('Config:', {
|
||||||
|
...Configuration._options,
|
||||||
|
username: '---scrubbed---',
|
||||||
|
password: '---scrubbed---',
|
||||||
|
mqttPassword: '---scrubbed---',
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Configuration;
|
module.exports = Configuration;
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,17 @@
|
||||||
|
const Configuration = require('./Configuration');
|
||||||
const Logger = require('./Logger');
|
const Logger = require('./Logger');
|
||||||
const PlejdAddon = require('./PlejdAddon');
|
const PlejdAddon = require('./PlejdAddon');
|
||||||
|
|
||||||
const logger = Logger.getLogger('plejd-main');
|
|
||||||
|
|
||||||
const version = '0.5.1';
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
logger.info(`Starting Plejd add-on v. ${version}`);
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('Starting Plejd addon and reading configuration...');
|
||||||
|
|
||||||
|
const addonInfo = Configuration.getAddonInfo();
|
||||||
|
const logger = Logger.getLogger('plejd-main');
|
||||||
|
|
||||||
|
logger.info(`Plejd add-on, version ${addonInfo.version}`);
|
||||||
|
logger.verbose(`Addon info: ${JSON.stringify(addonInfo)}`);
|
||||||
|
|
||||||
const addon = new PlejdAddon();
|
const addon = new PlejdAddon();
|
||||||
|
|
||||||
|
|
@ -15,7 +19,8 @@ async function main() {
|
||||||
|
|
||||||
logger.info('main() finished');
|
logger.info('main() finished');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('Catastrophic error. Resetting entire addon in 1 minute', err);
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('Catastrophic error. Resetting entire addon in 1 minute', err);
|
||||||
setTimeout(() => main(), 60000);
|
setTimeout(() => main(), 60000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue