Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Remove kibanaRoot option, require kibana-extra (elastic#58)
Browse files Browse the repository at this point in the history
* Remove kibanaRoot option, require kibana-extra

* Check location of Kibana on postinstall

* Fix eslint

* Remove 'process.env.KIBANA_ROOT'
  • Loading branch information
kimjoar authored and spalger committed Feb 8, 2018
1 parent b789537 commit 30ee7a4
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 26 deletions.
13 changes: 0 additions & 13 deletions packages/kbn-plugin-helpers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,6 @@ All configuration setting listed below can simply can be included in the json co

## Global settings

Setting | Description
------- | -----------
`kibanaRoot` | DEPRECATED. Path to your checkout of Kibana, relative paths are ok.

In the next major version of the plugin helpers the `kibanaRoot` setting can no longer be specified, and plugins must be located within the sibling `kibana-extra` folder, for example:

```sh
.
├── kibana
├── kibana-extra/foo-plugin
└── kibana-extra/bar-plugin
```

### Settings for `start`

Setting | Description
Expand Down
6 changes: 6 additions & 0 deletions packages/kbn-plugin-helpers/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,11 @@ program
});
}));

program
.command('postinstall')
.action(taskRunner(function (command) {
run('postinstall');
}));

program
.parse(process.argv);
20 changes: 8 additions & 12 deletions packages/kbn-plugin-helpers/lib/config_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const readFileSync = require('fs').readFileSync;

const configFiles = [ '.kibana-plugin-helpers.json', '.kibana-plugin-helpers.dev.json' ];
const configCache = {};
const KIBANA_ROOT_OVERRIDE = process.env.KIBANA_ROOT ? resolve(process.env.KIBANA_ROOT) : null;

module.exports = function (root) {
if (!root) root = process.cwd();
Expand All @@ -24,27 +23,24 @@ module.exports = function (root) {
}
});

const deprecationMsg = 'has been deprecated and is removed in the next ' +
'major version of `@elastic/plugin-helpers`.\n'
const deprecationMsg = 'has been removed from `@elastic/plugin-helpers`. ' +
'During development your plugin must be located in `../kibana-extra/{pluginName}` ' +
'relative to the Kibana directory to work with this package.\n'

if (config.kibanaRoot) {
process.stdout.write(
'WARNING: The `kibanaRoot` config option ' + deprecationMsg
throw new Error(
'The `kibanaRoot` config option ' + deprecationMsg
);
}
if (process.env.KIBANA_ROOT) {
process.stdout.write(
'WARNING: The `KIBANA_ROOT` environment variable ' + deprecationMsg
throw new Error(
'The `KIBANA_ROOT` environment variable ' + deprecationMsg
);
}

// use resolve to ensure correct resolution of paths
const { kibanaRoot, includePlugins } = config;
if (kibanaRoot) config.kibanaRoot = resolve(root, kibanaRoot);
const { includePlugins } = config;
if (includePlugins) config.includePlugins = includePlugins.map(path => resolve(root, path));

// allow env setting to override kibana root from config
if (KIBANA_ROOT_OVERRIDE) config.kibanaRoot = KIBANA_ROOT_OVERRIDE;

return config;
};
2 changes: 1 addition & 1 deletion packages/kbn-plugin-helpers/lib/plugin_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = function (root) {

return Object.assign({
root: root,
kibanaRoot: resolve(root, '../kibana'),
kibanaRoot: resolve(root, '../../kibana'),
serverTestPatterns: ['server/**/__tests__/**/*.js'],
buildSourcePatterns: buildSourcePatterns,
id: pkg.name,
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-plugin-helpers/lib/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ const startTask = require('../tasks/start');
const testAllTask = require('../tasks/test/all');
const testBrowserTask = require('../tasks/test/browser');
const testServerTask = require('../tasks/test/server');
const postinstallTask = require('../tasks/postinstall');

module.exports = {
build: buildTask,
start: startTask,
testAll: testAllTask,
testBrowser: testBrowserTask,
testServer: testServerTask,
postinstall: postinstallTask
};
25 changes: 25 additions & 0 deletions packages/kbn-plugin-helpers/tasks/postinstall/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const resolve = require('path').resolve;
const statSync = require('fs').statSync;

module.exports = function (plugin) {
if (
fileExists(resolve(plugin.root, '../kibana/package.json')) &&
!fileExists(resolve(plugin.root, '../../kibana/package.json'))
) {
process.stdout.write(
'\nWARNING: Kibana now requires that plugins must be located in ' +
'`../kibana-extra/{pluginName}` relative to the Kibana folder ' +
'during development. We found a Kibana in `../kibana`, but not in ' +
'`../../kibana`.\n'
);
}
};

function fileExists(path) {
try {
const stat = statSync(path);
return stat.isFile();
} catch (e) {
return false;
}
}

0 comments on commit 30ee7a4

Please sign in to comment.