mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-06-23 21:51:42 +00:00
4bc0c3ed6b
This allows specifying a path outside of the data directory using an absolute path (e.g. /path/to/devices.yaml) or a path relative to the data directory (e.g. devices.yaml, foo/devices.yaml, ../../devices.yaml, ...). This change is backward compatible because file names and nested paths are just a special case of a relative path. Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
30 lines
590 B
TypeScript
30 lines
590 B
TypeScript
import path from 'path';
|
|
|
|
let dataPath: string = null;
|
|
|
|
function load(): void {
|
|
if (process.env.ZIGBEE2MQTT_DATA) {
|
|
dataPath = process.env.ZIGBEE2MQTT_DATA;
|
|
} else {
|
|
dataPath = path.join(__dirname, '..', '..', 'data');
|
|
dataPath = path.normalize(dataPath);
|
|
}
|
|
}
|
|
|
|
load();
|
|
|
|
function joinPath(file: string): string {
|
|
return path.resolve(dataPath, file);
|
|
}
|
|
|
|
function getPath(): string {
|
|
return dataPath;
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
|
function testingOnlyReload(): void {
|
|
load();
|
|
}
|
|
|
|
export default {joinPath, getPath, testingOnlyReload};
|