* only modify root package.json file

previously this was modifying every package.json from node_modules as well

* refactor the build task

export the build, define helpers outside of the task

* allow custom kibana and build versions

both can be passed via flags

* allow custom build globs to be specified

* move build into its own module

* add simple option parsing tests

* update readme

* move dependency file appending into the action

* put source and target into variables

* move config file loading into a module

* refactor test_server_action slightly

be more explicit about the files option overwriting the plugin settings

* move default build patterns to plugin config

allows the setting to be overridden via the config file

* fix dirname on relative includes

trim any leading '../' off the path when moving it into the build target

* move node_module dirs into plugin_config module, use existing promises

* rename file_config => config_file

Original commit: elastic/kibana-plugin-helpers@743e4a37c2
This commit is contained in:
Joe Fleming 2016-12-21 21:37:57 -07:00 committed by Spencer
parent 4cc81e2c89
commit ceb52252be
8 changed files with 248 additions and 149 deletions

View file

@ -0,0 +1,30 @@
var resolve = require('path').resolve;
var readFileSync = require('fs').readFileSync;
var configFiles = [ '.kibana-plugin-helpers.json', '.kibana-plugin-helpers.dev.json' ];
var configCache = {};
module.exports = function (root) {
if (!root) root = process.cwd();
if (configCache[root]) {
return configCache[root];
}
// config files to read from, in the order they are merged together
var config = configCache[root] = {};
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 config;
};

View file

@ -1,29 +1,32 @@
var resolve = require('path').resolve;
var readFileSync = require('fs').readFileSync;
var configFile = require('./config_file');
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 = {};
var config = configFile(root);
configFiles.forEach(function (configFile) {
try {
var content = JSON.parse(readFileSync(resolve(root, configFile)));
config = Object.assign(config, content);
} catch (e) {
// noop
}
});
var buildSourcePatterns = [
'package.json',
'index.js',
'{lib,public,server,webpackShims}/**/*',
];
// if the kibanaRoot is set, use resolve to ensure correct resolution
if (config.kibanaRoot) config.kibanaRoot = resolve(root, config.kibanaRoot);
// add dependency files
var deps = Object.keys(pkg.dependencies || {});
if (deps.length === 1) {
buildSourcePatterns.push(`node_modules/${ deps[0] }/**/*`);
} else if (deps.length) {
buildSourcePatterns.push(`node_modules/{${ deps.join(',') }}/**/*`);
}
return Object.assign({
root: root,
kibanaRoot: resolve(root, '../kibana'),
serverTestPatterns: ['server/**/__tests__/**/*.js'],
buildSourcePatterns: buildSourcePatterns,
id: pkg.name,
pkg: pkg,
version: pkg.version,