2021-01-21 23:40:59 +01:00
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
|
|
class Configuration {
|
2021-02-01 21:12:05 +01:00
|
|
|
static _options = null;
|
2021-01-22 15:49:02 +01:00
|
|
|
|
2021-02-01 21:12:05 +01:00
|
|
|
static getOptions() {
|
|
|
|
|
if (!Configuration._options) {
|
2021-01-22 15:49:02 +01:00
|
|
|
const rawData = fs.readFileSync('/data/options.json');
|
2021-02-01 21:12:05 +01:00
|
|
|
const config = JSON.parse(rawData);
|
|
|
|
|
|
|
|
|
|
const defaultRawData = fs.readFileSync('/plejd/config.json');
|
|
|
|
|
const defaultConfig = JSON.parse(defaultRawData).options;
|
|
|
|
|
|
|
|
|
|
Configuration._options = { ...defaultConfig, ...config };
|
|
|
|
|
|
2021-02-01 21:36:40 +01:00
|
|
|
// eslint-disable-next-line no-console
|
2021-02-01 21:12:05 +01:00
|
|
|
console.log('Config:', {
|
|
|
|
|
...Configuration._options,
|
|
|
|
|
username: '---scrubbed---',
|
|
|
|
|
password: '---scrubbed---',
|
|
|
|
|
mqttPassword: '---scrubbed---',
|
|
|
|
|
});
|
2021-01-21 23:40:59 +01:00
|
|
|
}
|
2021-02-01 21:12:05 +01:00
|
|
|
return Configuration._options;
|
2021-01-22 15:49:02 +01:00
|
|
|
}
|
2021-01-21 23:40:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = Configuration;
|