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:
Vadim Dalecky 2020-04-17 20:15:36 +02:00 committed by GitHub
parent dc5c2f0e3f
commit b5762eb5ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 123 additions and 3 deletions

View file

@ -146,6 +146,7 @@ describe('OptimizerConfig::parseOptions()', () => {
<absolute path>/x-pack/plugins,
<absolute path>/plugins,
<absolute path>/examples,
<absolute path>/x-pack/examples,
<absolute path>-extra,
],
"profileWebpack": false,

View file

@ -91,14 +91,14 @@ export class OptimizerConfig {
/**
* 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
*/
const pluginScanDirs = options.pluginScanDirs || [
Path.resolve(repoRoot, 'src/plugins'),
...(oss ? [] : [Path.resolve(repoRoot, 'x-pack/plugins')]),
Path.resolve(repoRoot, 'plugins'),
...(examples ? [Path.resolve('examples')] : []),
...(examples ? [Path.resolve('examples'), Path.resolve('x-pack/examples')] : []),
Path.resolve(repoRoot, '../kibana-extra'),
];
if (!pluginScanDirs.every(p => Path.isAbsolute(p))) {

View file

@ -164,6 +164,17 @@ test('pluginSearchPaths contains examples plugins path if --run-examples flag is
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', () => {
const env = new Env(
'/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');
});
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');
});

View file

@ -109,7 +109,9 @@ export class Env {
resolve(this.homeDir, 'src', 'plugins'),
...(options.cliArgs.oss ? [] : [resolve(this.homeDir, 'x-pack', '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'),
];

View file

@ -44,6 +44,9 @@ export const PROJECTS = [
...glob
.sync('examples/*/tsconfig.json', { cwd: REPO_ROOT })
.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
.sync('test/plugin_functional/plugins/*/tsconfig.json', { cwd: REPO_ROOT })
.map(path => new Project(resolve(REPO_ROOT, path))),

View 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
```

View file

@ -0,0 +1,3 @@
## Ui actions enhanced examples
To run this example, use the command `yarn start --run-examples`.

View 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": []
}

View 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"
}
}

View file

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

View file

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

View file

@ -0,0 +1,15 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./target",
"skipLibCheck": true
},
"include": [
"index.ts",
"public/**/*.ts",
"public/**/*.tsx",
"server/**/*.ts",
"../../typings/**/*",
],
"exclude": []
}