configure datapath with env variable

This commit is contained in:
Daniel Welch
2018-05-11 23:04:15 -04:00
parent d583a61c9f
commit 03123fb783
5 changed files with 27 additions and 4 deletions
+7 -1
View File
@@ -1,4 +1,10 @@
const fs = require('fs');
const Controller = require('./lib/controller');
const data = require('./lib/util/data');
if (process.env.ZIGBEE2MQTT_DATA) {
fs.copyFileSync('./data/configuration.yaml', data.joinPath('configuration.yaml'))
}
const controller = new Controller();
controller.start();
@@ -7,4 +13,4 @@ process.on('SIGINT', handleQuit);
function handleQuit() {
controller.stop(() => process.exit());
}
}
+14
View File
@@ -0,0 +1,14 @@
const path = require('path');
function dataPath() {
if (process.env.ZIGBEE2MQTT_DATA) {
return process.env.ZIGBEE2MQTT_DATA;
} else {
return `${__dirname}/../../data`;
}
}
module.exports = {
path: dataPath(),
joinPath: (file) => path.join(dataPath(), file)
}
+2 -1
View File
@@ -1,9 +1,10 @@
const winston = require('winston');
const data = require('./data');
const logger = new (winston.Logger)({
transports: [
new (winston.transports.File)({
filename: 'data/log.txt',
filename: data.joinPath('log.txt'),
json: false,
level: winston.level.info,
maxFiles: 3,
+2 -1
View File
@@ -1,6 +1,7 @@
const YAWN = require('yawn-yaml/cjs');
const fs = require('fs');
const file = `${__dirname}/../../data/configuration.yaml`;
const data = require('./data');
let file = data.joinPath('configuration.yaml');
let yawn = read();
function write() {
+2 -1
View File
@@ -2,10 +2,11 @@ const ZShepherd = require('zigbee-shepherd');
const logger = require('./util/logger');
const settings = require('./util/settings');
const deviceMapping = require('./devices');
const data = require('./util/data');
const shepherdSettings = {
net: {panId: 0x1a62},
dbPath: `${__dirname}/../data/database.db`
dbPath: data.joinPath('database.db')
};
class Zigbee {