mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Use json files to override default config values (elastic/kibana-plugin-helpers#21)
* read json overrides, mix into defaults * rename plugin config helper * use the plugin config in start Original commit: elastic/kibana-plugin-helpers@4cfbe28128
This commit is contained in:
parent
0632b8e2b9
commit
43c6f9c660
5 changed files with 35 additions and 22 deletions
|
@ -1,15 +0,0 @@
|
|||
var resolve = require('path').resolve;
|
||||
|
||||
module.exports = function (root) {
|
||||
if (!root) root = process.cwd();
|
||||
var pkg = require(resolve(root, 'package.json'));
|
||||
|
||||
return {
|
||||
root: root,
|
||||
kibanaRoot: resolve(root, '../kibana'),
|
||||
id: pkg.name,
|
||||
pkg: pkg,
|
||||
version: pkg.version,
|
||||
config: (pkg.config && pkg.config.kibanaPluginHelpers) || {}
|
||||
};
|
||||
};
|
30
packages/kbn-plugin-helpers/lib/plugin_config.js
Normal file
30
packages/kbn-plugin-helpers/lib/plugin_config.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
var resolve = require('path').resolve;
|
||||
var readFileSync = require('fs').readFileSync;
|
||||
|
||||
module.exports = function (root) {
|
||||
if (!root) root = process.cwd();
|
||||
var pkg = require(resolve(root, 'package.json'));
|
||||
// config files to read from, in the order they are merged together
|
||||
var configFiles = [ '.kibana-plugin-helpers.json', '.kibana-plugin-helpers.dev.json' ];
|
||||
var config = {};
|
||||
|
||||
configFiles.forEach(function (configFile) {
|
||||
try {
|
||||
var content = JSON.parse(readFileSync(resolve(root, configFile)));
|
||||
config = Object.assign(config, content);
|
||||
} catch (e) {
|
||||
// noop
|
||||
}
|
||||
});
|
||||
|
||||
// if the kibanaRoot is set, use resolve to ensure correct resolution
|
||||
if (config.kibanaRoot) config.kibanaRoot = resolve(root, config.kibanaRoot);
|
||||
|
||||
return Object.assign({
|
||||
root: root,
|
||||
kibanaRoot: resolve(root, '../kibana'),
|
||||
id: pkg.name,
|
||||
pkg: pkg,
|
||||
version: pkg.version,
|
||||
}, config);
|
||||
};
|
|
@ -1,10 +1,11 @@
|
|||
var idPlugin = require('./id_plugin');
|
||||
var pluginConfig = require('./plugin_config');
|
||||
|
||||
module.exports = function run(name) {
|
||||
var action = require('../tasks/' + name);
|
||||
return function () {
|
||||
// call the action function with the plugin, then all
|
||||
// renaining arguments from commander
|
||||
action.apply(null, [idPlugin()].concat([].slice.apply(arguments)));
|
||||
var plugin = pluginConfig();
|
||||
action.apply(null, [plugin].concat([].slice.apply(arguments)));
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue