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:
Joe Fleming 2016-12-14 17:03:15 -07:00 committed by Spencer
parent 0632b8e2b9
commit 43c6f9c660
5 changed files with 35 additions and 22 deletions

View file

@ -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) || {}
};
};

View 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);
};

View file

@ -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)));
};
};

View file

@ -7,7 +7,7 @@ const buildAction = require('./build_action');
const PLUGIN_FIXTURE = resolve(__dirname, '__fixtures__/test_plugin');
const PLUGIN_BUILD_DIR = resolve(PLUGIN_FIXTURE, 'build');
const PLUGIN = require('../../lib/id_plugin')(PLUGIN_FIXTURE);
const PLUGIN = require('../../lib/plugin_config')(PLUGIN_FIXTURE);
describe('build_action', () => {
beforeEach(() => del(PLUGIN_BUILD_DIR));

View file

@ -1,13 +1,10 @@
module.exports = function (plugin, command) {
var resolve = require('path').resolve;
var execFileSync = require('child_process').execFileSync;
var kibanaDir = resolve(plugin.root, '../kibana');
var cmd = (process.platform === 'win32') ? 'bin\\kibana.bat' : 'bin/kibana';
var args = ['--dev', '--plugin-path', plugin.root, ...command.unkownOptions];
execFileSync(cmd, args, {
cwd: kibanaDir,
cwd: plugin.kibanaRoot,
stdio: ['ignore', 1, 2]
});
};