UNPKG

1.18 kBJavaScriptView Raw
1const resolve = require('path').resolve;
2const readFileSync = require('fs').readFileSync;
3
4const configFiles = [ '.kibana-plugin-helpers.json', '.kibana-plugin-helpers.dev.json' ];
5const configCache = {};
6const KIBANA_ROOT_OVERRIDE = process.env.KIBANA_ROOT ? resolve(process.env.KIBANA_ROOT) : null;
7
8module.exports = function (root) {
9 if (!root) root = process.cwd();
10
11 if (configCache[root]) {
12 return configCache[root];
13 }
14
15 // config files to read from, in the order they are merged together
16 let config = configCache[root] = {};
17
18 configFiles.forEach(function (configFile) {
19 try {
20 const content = JSON.parse(readFileSync(resolve(root, configFile)));
21 config = Object.assign(config, content);
22 } catch (e) {
23 // noop
24 }
25 });
26
27 // use resolve to ensure correct resolution of paths
28 const { kibanaRoot, includePlugins } = config;
29 if (kibanaRoot) config.kibanaRoot = resolve(root, kibanaRoot);
30 if (includePlugins) config.includePlugins = includePlugins.map(path => resolve(root, path));
31
32 // allow env setting to override kibana root from config
33 if (KIBANA_ROOT_OVERRIDE) config.kibanaRoot = KIBANA_ROOT_OVERRIDE;
34
35 return config;
36};