Skip to content

Commit

Permalink
Add docs + generator changes
Browse files Browse the repository at this point in the history
  • Loading branch information
afharo committed Nov 10, 2023
1 parent 0404c34 commit a7038ae
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
13 changes: 11 additions & 2 deletions dev_docs/key_concepts/anatomy_of_a_plugin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ If you are developing in TypeScript (which we recommend), you will need to add a
core capabilities as an argument. It should return an instance of its plugin class for Kibana to load.

```ts
import type { PluginInitializerContext } from '@kbn/core/server';
import type { PluginInitializerContext } from '@kbn/core/public';
import { DemoPlugin } from './plugin';

export function plugin(initializerContext: PluginInitializerContext) {
Expand Down Expand Up @@ -177,7 +177,16 @@ export class DemoPlugin implements Plugin {

### server/index.ts

`server/index.ts` is the entry-point into the server-side code of this plugin. It is identical in almost every way to the client-side entry-point:
`server/index.ts` is the entry-point into the server-side code of this plugin.

```ts
import type { PluginInitializerContext } from '@kbn/core/server';

export async function plugin(initializerContext: PluginInitializerContext) {
const { DemoPlugin } = await import('./plugin');
return new DemoPlugin(initializerContext);
}
```

### server/plugin.ts

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export type MyPluginConfigType = TypeOf<typeof config.schema>;

* Read config value exposed via `PluginInitializerContext`:

*my_plugin/server/index.ts*
*my_plugin/server/plugin.ts*
[source,typescript]
----
import type { PluginInitializerContext } from '@kbn/core/server';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ entry-point:
[source,typescript]
----
import type { PluginInitializerContext } from '@kbn/core/server';
import { MyPlugin } from './plugin';
export function plugin(initializerContext: PluginInitializerContext) {
export async function plugin(initializerContext: PluginInitializerContext) {
const { MyPlugin } = await import('./plugin');
return new MyPlugin(initializerContext);
}
----
Expand Down
5 changes: 2 additions & 3 deletions packages/kbn-plugin-generator/template/server/index.ts.ejs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { PluginInitializerContext } from '<%= importFromRoot('src/core/server') %>';
import { <%= upperCamelCase(name) %>Plugin } from './plugin';


// This exports static code and TypeScript types,
// as well as, Kibana Platform `plugin()` initializer.

export function plugin(initializerContext: PluginInitializerContext) {
export async function plugin(initializerContext: PluginInitializerContext) {
const { <%= upperCamelCase(name) %>Plugin } = await import('./plugin');
return new <%= upperCamelCase(name) %>Plugin(initializerContext);
}

Expand Down

0 comments on commit a7038ae

Please sign in to comment.