Skip to content

Commit

Permalink
Example plugins in X-Pack (#63823) (#63890)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
streamich authored Apr 18, 2020
1 parent f1fb12b commit 06c62cf
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-optimizer/src/optimizer/optimizer_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down
22 changes: 22 additions & 0 deletions src/core/server/config/env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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');
});
4 changes: 3 additions & 1 deletion src/core/server/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
];

Expand Down
3 changes: 3 additions & 0 deletions src/dev/typescript/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
Expand Down
7 changes: 7 additions & 0 deletions x-pack/examples/README.md
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions x-pack/examples/ui_actions_enhanced_examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Ui actions enhanced examples

To run this example, use the command `yarn start --run-examples`.
10 changes: 10 additions & 0 deletions x-pack/examples/ui_actions_enhanced_examples/kibana.json
Original file line number Diff line number Diff line change
@@ -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 changes: 17 additions & 0 deletions x-pack/examples/ui_actions_enhanced_examples/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
9 changes: 9 additions & 0 deletions x-pack/examples/ui_actions_enhanced_examples/public/index.ts
Original file line number Diff line number Diff line change
@@ -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();
31 changes: 31 additions & 0 deletions x-pack/examples/ui_actions_enhanced_examples/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions x-pack/examples/ui_actions_enhanced_examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./target",
"skipLibCheck": true
},
"include": [
"index.ts",
"public/**/*.ts",
"public/**/*.tsx",
"server/**/*.ts",
"../../typings/**/*",
],
"exclude": []
}

0 comments on commit 06c62cf

Please sign in to comment.