zigbee2mqtt/lib/util/data.js
Koen Kanters a54e256b40
Group configuration via configuration.yaml and group state (#1464)
Group configuration via configuration.yaml and group state.
2019-04-29 20:38:40 +02:00

34 lines
744 B
JavaScript

const path = require('path');
const fs = require('fs');
let dataPath = null;
function load() {
if (process.env.ZIGBEE2MQTT_DATA) {
dataPath = process.env.ZIGBEE2MQTT_DATA;
} else {
dataPath = path.join(__dirname, '..', '..', 'data');
dataPath = path.normalize(dataPath);
}
}
load();
function joinPathStorage(file) {
const storagePath = path.join(dataPath, '.storage');
if (!fs.existsSync(storagePath)) {
fs.mkdirSync(storagePath);
}
return path.join(storagePath, file);
}
module.exports = {
joinPath: (file) => path.join(dataPath, file),
joinPathStorage: (file) => joinPathStorage(file),
getPath: () => dataPath,
// For test only.
_reload: () => load(),
};