forked from Automattic/simplenote-electron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-config.js
39 lines (35 loc) · 982 Bytes
/
get-config.js
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
function readLocalConfig() {
try {
const config = require('./config-local');
if (typeof config === 'function') {
throw new Error('Invalid config file. Config must be JSON.');
}
return config;
} catch {
return false;
}
}
function readConfig() {
try {
const config = require('./config');
if (typeof config === 'function') {
throw new Error('Invalid config file. Config must be JSON.');
}
return config;
} catch (e) {
// eslint-disable-next-line no-console
console.error(
'Could not read in the required configuration file.\n' +
'This file should exist as `config.json` inside the project root directory.\n' +
'Please consult the project README.md for further information.\n'
);
throw e;
}
}
function getConfig() {
var config = readLocalConfig() || readConfig();
var pkg = require('./package.json');
config.version = pkg.version;
return config;
}
module.exports = getConfig;