1 | const resolve = require('path').resolve;
|
2 | const readFileSync = require('fs').readFileSync;
|
3 |
|
4 | const configFiles = [ '.kibana-plugin-helpers.json', '.kibana-plugin-helpers.dev.json' ];
|
5 | const configCache = {};
|
6 | const KIBANA_ROOT_OVERRIDE = process.env.KIBANA_ROOT ? resolve(process.env.KIBANA_ROOT) : null;
|
7 |
|
8 | module.exports = function (root) {
|
9 | if (!root) root = process.cwd();
|
10 |
|
11 | if (configCache[root]) {
|
12 | return configCache[root];
|
13 | }
|
14 |
|
15 |
|
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 |
|
24 | }
|
25 | });
|
26 |
|
27 |
|
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 |
|
33 | if (KIBANA_ROOT_OVERRIDE) config.kibanaRoot = KIBANA_ROOT_OVERRIDE;
|
34 |
|
35 | return config;
|
36 | };
|