-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetConfig.js
More file actions
45 lines (41 loc) · 974 Bytes
/
getConfig.js
File metadata and controls
45 lines (41 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"use strict";
const path = require("path");
const os = require("os");
const paths = [
"./streamDeckrc.json",
"./streamdeckrc.json",
path.join(require("os").homedir(), "/streamDeckrc.json"),
path.join(require("os").homedir(), "/streamdeckrc.json"),
path.join(
require("os").homedir(),
"/.local/share/streamDeckrc.json"
),
path.join(
require("os").homedir(),
"/.local/share/streamdeckrc.json"
)
];
const getConfig = (pathIndex = 0) => {
let config;
try {
const maybeConfig = require(paths[pathIndex]);
if (maybeConfig) {
config = maybeConfig;
console.log("config found at: ", paths[pathIndex]);
}
} catch (err) {
console.log(
"warning during config search",
err.message
);
}
if (config) {
return config;
}
if (paths[pathIndex + 1]) {
return getConfig(pathIndex + 1);
}
console.log("unable to locate config file");
return process.exit();
};
module.exports = getConfig;