Example plugins in X-Pack (#63823)
* feat: 🎸 add example plugin ability to X-Pack * style: 💄 spread array items from one array * chore: 🤖 add x-pack/examples tsconfigs to global list * fix: 🐛 don't import non-existing plugin * fix: 🐛 fix TypeScript error * test: 💍 update Jest snapshot
This commit is contained in:
parent
dc5c2f0e3f
commit
b5762eb5ff
|
@ -146,6 +146,7 @@ describe('OptimizerConfig::parseOptions()', () => {
|
||||||
<absolute path>/x-pack/plugins,
|
<absolute path>/x-pack/plugins,
|
||||||
<absolute path>/plugins,
|
<absolute path>/plugins,
|
||||||
<absolute path>/examples,
|
<absolute path>/examples,
|
||||||
|
<absolute path>/x-pack/examples,
|
||||||
<absolute path>-extra,
|
<absolute path>-extra,
|
||||||
],
|
],
|
||||||
"profileWebpack": false,
|
"profileWebpack": false,
|
||||||
|
|
|
@ -91,14 +91,14 @@ export class OptimizerConfig {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BEWARE: this needs to stay roughly synchronized with
|
* BEWARE: this needs to stay roughly synchronized with
|
||||||
* `src/core/server/config/env.ts` which determins which paths
|
* `src/core/server/config/env.ts` which determines which paths
|
||||||
* should be searched for plugins to load
|
* should be searched for plugins to load
|
||||||
*/
|
*/
|
||||||
const pluginScanDirs = options.pluginScanDirs || [
|
const pluginScanDirs = options.pluginScanDirs || [
|
||||||
Path.resolve(repoRoot, 'src/plugins'),
|
Path.resolve(repoRoot, 'src/plugins'),
|
||||||
...(oss ? [] : [Path.resolve(repoRoot, 'x-pack/plugins')]),
|
...(oss ? [] : [Path.resolve(repoRoot, 'x-pack/plugins')]),
|
||||||
Path.resolve(repoRoot, 'plugins'),
|
Path.resolve(repoRoot, 'plugins'),
|
||||||
...(examples ? [Path.resolve('examples')] : []),
|
...(examples ? [Path.resolve('examples'), Path.resolve('x-pack/examples')] : []),
|
||||||
Path.resolve(repoRoot, '../kibana-extra'),
|
Path.resolve(repoRoot, '../kibana-extra'),
|
||||||
];
|
];
|
||||||
if (!pluginScanDirs.every(p => Path.isAbsolute(p))) {
|
if (!pluginScanDirs.every(p => Path.isAbsolute(p))) {
|
||||||
|
|
|
@ -164,6 +164,17 @@ test('pluginSearchPaths contains examples plugins path if --run-examples flag is
|
||||||
expect(env.pluginSearchPaths).toContain('/some/home/dir/examples');
|
expect(env.pluginSearchPaths).toContain('/some/home/dir/examples');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('pluginSearchPaths contains x-pack/examples plugins path if --run-examples flag is true', () => {
|
||||||
|
const env = new Env(
|
||||||
|
'/some/home/dir',
|
||||||
|
getEnvOptions({
|
||||||
|
cliArgs: { runExamples: true },
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(env.pluginSearchPaths).toContain('/some/home/dir/x-pack/examples');
|
||||||
|
});
|
||||||
|
|
||||||
test('pluginSearchPaths does not contains examples plugins path if --run-examples flag is false', () => {
|
test('pluginSearchPaths does not contains examples plugins path if --run-examples flag is false', () => {
|
||||||
const env = new Env(
|
const env = new Env(
|
||||||
'/some/home/dir',
|
'/some/home/dir',
|
||||||
|
@ -174,3 +185,14 @@ test('pluginSearchPaths does not contains examples plugins path if --run-example
|
||||||
|
|
||||||
expect(env.pluginSearchPaths).not.toContain('/some/home/dir/examples');
|
expect(env.pluginSearchPaths).not.toContain('/some/home/dir/examples');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('pluginSearchPaths does not contains x-pack/examples plugins path if --run-examples flag is false', () => {
|
||||||
|
const env = new Env(
|
||||||
|
'/some/home/dir',
|
||||||
|
getEnvOptions({
|
||||||
|
cliArgs: { runExamples: false },
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(env.pluginSearchPaths).not.toContain('/some/home/dir/x-pack/examples');
|
||||||
|
});
|
||||||
|
|
|
@ -109,7 +109,9 @@ export class Env {
|
||||||
resolve(this.homeDir, 'src', 'plugins'),
|
resolve(this.homeDir, 'src', 'plugins'),
|
||||||
...(options.cliArgs.oss ? [] : [resolve(this.homeDir, 'x-pack', 'plugins')]),
|
...(options.cliArgs.oss ? [] : [resolve(this.homeDir, 'x-pack', 'plugins')]),
|
||||||
resolve(this.homeDir, 'plugins'),
|
resolve(this.homeDir, 'plugins'),
|
||||||
...(options.cliArgs.runExamples ? [resolve(this.homeDir, 'examples')] : []),
|
...(options.cliArgs.runExamples
|
||||||
|
? [resolve(this.homeDir, 'examples'), resolve(this.homeDir, 'x-pack', 'examples')]
|
||||||
|
: []),
|
||||||
resolve(this.homeDir, '..', 'kibana-extra'),
|
resolve(this.homeDir, '..', 'kibana-extra'),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,9 @@ export const PROJECTS = [
|
||||||
...glob
|
...glob
|
||||||
.sync('examples/*/tsconfig.json', { cwd: REPO_ROOT })
|
.sync('examples/*/tsconfig.json', { cwd: REPO_ROOT })
|
||||||
.map(path => new Project(resolve(REPO_ROOT, path))),
|
.map(path => new Project(resolve(REPO_ROOT, path))),
|
||||||
|
...glob
|
||||||
|
.sync('x-pack/examples/*/tsconfig.json', { cwd: REPO_ROOT })
|
||||||
|
.map(path => new Project(resolve(REPO_ROOT, path))),
|
||||||
...glob
|
...glob
|
||||||
.sync('test/plugin_functional/plugins/*/tsconfig.json', { cwd: REPO_ROOT })
|
.sync('test/plugin_functional/plugins/*/tsconfig.json', { cwd: REPO_ROOT })
|
||||||
.map(path => new Project(resolve(REPO_ROOT, path))),
|
.map(path => new Project(resolve(REPO_ROOT, path))),
|
||||||
|
|
7
x-pack/examples/README.md
Normal file
7
x-pack/examples/README.md
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
## Example plugins
|
||||||
|
|
||||||
|
This folder contains X-Pack example plugins. To run the plugins in this folder, use the `--run-examples` flag, via
|
||||||
|
|
||||||
|
```
|
||||||
|
yarn start --run-examples
|
||||||
|
```
|
3
x-pack/examples/ui_actions_enhanced_examples/README.md
Normal file
3
x-pack/examples/ui_actions_enhanced_examples/README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
## Ui actions enhanced examples
|
||||||
|
|
||||||
|
To run this example, use the command `yarn start --run-examples`.
|
10
x-pack/examples/ui_actions_enhanced_examples/kibana.json
Normal file
10
x-pack/examples/ui_actions_enhanced_examples/kibana.json
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"id": "uiActionsEnhancedExamples",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"kibanaVersion": "kibana",
|
||||||
|
"configPath": ["ui_actions_enhanced_examples"],
|
||||||
|
"server": false,
|
||||||
|
"ui": true,
|
||||||
|
"requiredPlugins": ["uiActions", "data"],
|
||||||
|
"optionalPlugins": []
|
||||||
|
}
|
17
x-pack/examples/ui_actions_enhanced_examples/package.json
Normal file
17
x-pack/examples/ui_actions_enhanced_examples/package.json
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"name": "ui_actions_enhanced_examples",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "target/examples/ui_actions_enhanced_examples",
|
||||||
|
"kibana": {
|
||||||
|
"version": "kibana",
|
||||||
|
"templateVersion": "1.0.0"
|
||||||
|
},
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"scripts": {
|
||||||
|
"kbn": "node ../../scripts/kbn.js",
|
||||||
|
"build": "rm -rf './target' && tsc"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"typescript": "3.7.2"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License;
|
||||||
|
* you may not use this file except in compliance with the Elastic License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { UiActionsEnhancedExamplesPlugin } from './plugin';
|
||||||
|
|
||||||
|
export const plugin = () => new UiActionsEnhancedExamplesPlugin();
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License;
|
||||||
|
* you may not use this file except in compliance with the Elastic License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Plugin, CoreSetup, CoreStart } from '../../../../src/core/public';
|
||||||
|
import { UiActionsSetup, UiActionsStart } from '../../../../src/plugins/ui_actions/public';
|
||||||
|
import { DataPublicPluginSetup, DataPublicPluginStart } from '../../../../src/plugins/data/public';
|
||||||
|
|
||||||
|
export interface SetupDependencies {
|
||||||
|
data: DataPublicPluginSetup;
|
||||||
|
uiActions: UiActionsSetup;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StartDependencies {
|
||||||
|
data: DataPublicPluginStart;
|
||||||
|
uiActions: UiActionsStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class UiActionsEnhancedExamplesPlugin
|
||||||
|
implements Plugin<void, void, SetupDependencies, StartDependencies> {
|
||||||
|
public setup(core: CoreSetup<StartDependencies>, plugins: SetupDependencies) {
|
||||||
|
// eslint-disable-next-line
|
||||||
|
console.log('ui_actions_enhanced_examples');
|
||||||
|
}
|
||||||
|
|
||||||
|
public start(core: CoreStart, plugins: StartDependencies) {}
|
||||||
|
|
||||||
|
public stop() {}
|
||||||
|
}
|
15
x-pack/examples/ui_actions_enhanced_examples/tsconfig.json
Normal file
15
x-pack/examples/ui_actions_enhanced_examples/tsconfig.json
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"extends": "../../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./target",
|
||||||
|
"skipLibCheck": true
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"index.ts",
|
||||||
|
"public/**/*.ts",
|
||||||
|
"public/**/*.tsx",
|
||||||
|
"server/**/*.ts",
|
||||||
|
"../../typings/**/*",
|
||||||
|
],
|
||||||
|
"exclude": []
|
||||||
|
}
|
Loading…
Reference in a new issue