Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update plugin generator to generate NP plugins #55281

Merged
merged 31 commits into from
Feb 3, 2020
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5eb5357
Generate NP plugin
Jan 19, 2020
f44b2c3
Added tsconfig
Jan 20, 2020
65e621d
tsconfig
Jan 20, 2020
b972827
Adjust sao test
Jan 20, 2020
3fa50aa
Add server side to plugin gen
Jan 20, 2020
fed27b5
Added navigation
Jan 20, 2020
7dbb585
add empty element
Jan 20, 2020
3f8520a
eslint
Jan 21, 2020
7f5e363
platform team CR
Jan 23, 2020
7ad1324
design CR improvements
Jan 23, 2020
c5a8ab0
Merge remote-tracking branch 'upstream/master' into newplatform/plugi…
Jan 23, 2020
055a63a
text updates
Jan 26, 2020
33c2680
temp disable plugin gen tests
Jan 26, 2020
9f2bcb8
Merge remote-tracking branch 'upstream/master' into newplatform/plugi…
Jan 26, 2020
d11db3a
Merge branch 'master' into newplatform/plugin-gen
elasticmachine Jan 28, 2020
e7c15c5
Merge branch 'master' of github.com:elastic/kibana into newplatform/p…
Jan 29, 2020
0dfa19f
eslint
Jan 29, 2020
7279243
Merge branch 'newplatform/plugin-gen' of github.com:lizozom/kibana in…
Jan 29, 2020
47b7bef
Code review fixes
Jan 29, 2020
38aee60
Add scss support - requires #53976 to be merged to work
Jan 29, 2020
a9d471b
CR fixes
Jan 30, 2020
5e3f3dc
comment fixes
Jan 30, 2020
5a3ceff
Merge branch 'master' of github.com:elastic/kibana into newplatform/p…
Jan 30, 2020
b91ee61
Don't generate eslint for internal plugins by default
Jan 30, 2020
09b2375
Update tests
Jan 30, 2020
2a9e1ff
reenable jest test for sao
Jan 30, 2020
1952d75
Fix regex
Jan 30, 2020
0b9ca29
review comments
Jan 30, 2020
1ff8556
Merge branch 'master' of github.com:elastic/kibana into newplatform/p…
Feb 2, 2020
8ad025e
code review
Feb 2, 2020
8274c78
Merge branch 'master' into newplatform/plugin-gen
elasticmachine Feb 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add server side to plugin gen
Liza K committed Jan 20, 2020
commit 3fa50aa814235141e6da42bd08a60c986521d5e4
2 changes: 1 addition & 1 deletion packages/kbn-plugin-generator/index.js.d.ts
Original file line number Diff line number Diff line change
@@ -20,5 +20,5 @@ interface PluginGenerator {
/**
* Run plugin generator.
*/
run: any;
run: (...args: any[]) => any;
}
2 changes: 1 addition & 1 deletion packages/kbn-plugin-generator/sao_template/sao.js
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ module.exports = function({ name, targetPath, isKibanaPlugin }) {
snakeCase,
name,
kbnVersion: answers.kbnVersion,
camelCaseName: name.charAt(0).toUpperCase() + camelCase(name).slice(1),
upperCamelCaseName: name.charAt(0).toUpperCase() + camelCase(name).slice(1),
hasUi: !!answers.generateApp,
hasServer: !!answers.generateApi,
relRoot: isKibanaPlugin ? '../../../..' : '../../..',
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const PLUGIN_ID = '<%= camelCase(name) %>';
export const PLUGIN_NAME = '<%= name %>';
export const PLUGIN_NAME = '<%= name %>';
15 changes: 7 additions & 8 deletions packages/kbn-plugin-generator/sao_template/template/kibana.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"id": "<%= camelCase(name) %>",
"version": "<%= kbnVersion %>",
"server": <%= hasServer %>,
"ui": <%= hasUi %>,
"requiredPlugins": [],
"optionalPlugins": []
}

"id": "<%= camelCase(name) %>",
"version": "<%= kbnVersion %>",
"server": <%= hasServer %>,
"ui": <%= hasUi %>,
"requiredPlugins": [],
"optionalPlugins": []
}
Original file line number Diff line number Diff line change
@@ -17,12 +17,13 @@
* under the License.
*/

import React from 'react';
import React, { useState } from 'react';
import ReactDOM from 'react-dom';
import { FormattedMessage } from '@kbn/i18n/react';
import { BrowserRouter as Router, Route, withRouter, RouteComponentProps } from 'react-router-dom';
import { FormattedMessage, I18nProvider } from '@kbn/i18n/react';
import { BrowserRouter as Router } from 'react-router-dom';

import {
EuiButton,
EuiPage,
EuiPageBody,
EuiPageContent,
@@ -33,61 +34,94 @@ import {
EuiText,
} from '@elastic/eui';

import { AppMountContext, AppMountParameters } from '<%= relRoot %>/../src/core/public';
import { AppMountParameters, CoreStart } from '<%= relRoot %>/../src/core/public';
lizozom marked this conversation as resolved.
Show resolved Hide resolved

const FooApp = ({ basename, context }: { basename: string; context: AppMountContext }) => (
<Router basename={basename}>
<EuiPage>
<EuiPageBody>
<EuiPageHeader>
<EuiTitle size="l">
<h1>
<FormattedMessage
id="liz.helloWorldText"
defaultMessage="Hello World!"
/>
</h1>
</EuiTitle>
</EuiPageHeader>
<EuiPageContent>
<EuiPageContentHeader>
<EuiTitle>
<h2>
import { PLUGIN_NAME } from '../../common';

interface <%= upperCamelCaseName %>AppDeps {
basename: string;
notifications: CoreStart['notifications'];
http: CoreStart['http'];
};

const <%= upperCamelCaseName %>App = ({ basename, notifications, http }: <%= upperCamelCaseName %>AppDeps) => {
const [timestamp, setTimestamp] = useState<string | undefined>();

const fetchData = () => {
http.get('/api/<%= snakeCase(name) %>/example').then((res) => {
setTimestamp(res.time);
notifications.toasts.addSuccess(PLUGIN_NAME);
});
};

return (
<Router basename={basename}>
<I18nProvider>
<EuiPage>
<EuiPageBody>
<EuiPageHeader>
<EuiTitle size="l">
<h1>
<FormattedMessage
id="liz.congratulationsTitle"
defaultMessage="Congratulations"
id="<%= camelCase(name) %>.helloWorldText"
defaultMessage="Hello {name}!"
values={{ name: PLUGIN_NAME }}
/>
</h2>
</h1>
</EuiTitle>
</EuiPageContentHeader>
<EuiPageContentBody>
<EuiText>
<h3>
<FormattedMessage
id="liz.congratulationsText"
defaultMessage="You have successfully created your first Kibana Plugin!"
/>
</h3>
<p>
<FormattedMessage
id="liz.serverTimeText"
defaultMessage="The server time (via API call) is {time}"
values={{ time: 'NO API CALL YET' }}
/>
</p>
</EuiText>
</EuiPageContentBody>
</EuiPageContent>
</EuiPageBody>
</EuiPage>
</Router>
);
</EuiPageHeader>
<EuiPageContent>
<EuiPageContentHeader>
<EuiTitle>
<h2>
<FormattedMessage
id="<%= camelCase(name) %>.congratulationsTitle"
defaultMessage="Congratulations"
/>
</h2>
</EuiTitle>
</EuiPageContentHeader>
<EuiPageContentBody>
<EuiText>
<h3>
<FormattedMessage
id="<%= camelCase(name) %>.congratulationsText"
defaultMessage="You have successfully created your first Kibana Plugin!"
/>
</h3>
<p>
<FormattedMessage
id="banana.serverTimeText"
defaultMessage="Last response from server: {time}"
values={{ time: timestamp ? timestamp : 'Unknown' }}
/>
</p>
<EuiButton
type="primary"
size="s"
onClick={fetchData}
>
<FormattedMessage
id="<%= camelCase(name) %>.buttonText"
defaultMessage="Fetch data"
/>
</EuiButton>
</EuiText>
</EuiPageContentBody>
</EuiPageContent>
</EuiPageBody>
</EuiPage>
</I18nProvider>
</Router>
);
};

export const renderApp = (
context: AppMountContext,
{ notifications, http }: CoreStart,
{}: any,
{ appBasePath, element }: AppMountParameters
) => {
ReactDOM.render(<FooApp basename={appBasePath} context={context} />, element);
ReactDOM.render(<<%= upperCamelCaseName %>App basename={appBasePath} notifications={notifications} http={http}/>, element);

return () => ReactDOM.unmountComponentAtNode(element);
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@


import { PluginInitializerContext } from '<%= relRoot %>/src/core/public';
export function plugin(initializerContext: PluginInitializerContext) {
return new <%= camelCaseName %>PublicPlugin(initializerContext);
export function plugin() {
return new <%= upperCamelCaseName %>PublicPlugin();
}

lizozom marked this conversation as resolved.
Show resolved Hide resolved
export * from '../common';
export * from './types';

// Export plugin after all other imports
import { <%= camelCaseName %>PublicPlugin } from './plugin';
export { <%= camelCaseName %>PublicPlugin as Plugin };
import { <%= upperCamelCaseName %>PublicPlugin } from './plugin';
export { <%= upperCamelCaseName %>PublicPlugin as Plugin };
lizozom marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
import { PluginInitializerContext, CoreSetup, CoreStart, Plugin, AppMountContext } from '<%= relRoot %>/src/core/public';
import { CoreSetup, CoreStart, Plugin } from '<%= relRoot %>/src/core/public';
import {
<%= camelCaseName %>PublicPluginSetup,
<%= camelCaseName %>PublicPluginStart,
<%= upperCamelCaseName %>PublicPluginSetup,
<%= upperCamelCaseName %>PublicPluginStart,
} from './types';
import { i18n } from '@kbn/i18n';
import { PLUGIN_NAME } from '../common';

export class <%= camelCaseName %>PublicPlugin implements Plugin<<%= camelCaseName %>PublicPluginSetup, <%= camelCaseName %>PublicPluginStart> {
constructor(initializerContext: PluginInitializerContext) {
}

public setup(core: CoreSetup): <%= camelCaseName %>PublicPluginSetup {
export class <%= upperCamelCaseName %>PublicPlugin implements Plugin<<%= upperCamelCaseName %>PublicPluginSetup, <%= upperCamelCaseName %>PublicPluginStart> {
public setup(core: CoreSetup): <%= upperCamelCaseName %>PublicPluginSetup {
core.application.register({
id: '<%= camelCase(name) %>',
title: PLUGIN_NAME,
async mount(context: AppMountContext, params: any) {
async mount(params) {
lizozom marked this conversation as resolved.
Show resolved Hide resolved
// Load application bundle
const { renderApp } = await import('./components/app');
return renderApp(context, params);
},
// Get start services
const [coreStart, depsStart] = await core.getStartServices();
return renderApp(coreStart, depsStart, params);
}
});

// Return any methods that should be available to other plugins
return {
getGreeting() {
return 'Hello from Plugin A!';
return i18n.translate('<%= camelCase(name) %>.greetingText', {
defaultMessage: 'Hello from {name}!',
values: {
name: PLUGIN_NAME,
},
});
},
};
}

public start(core: CoreStart): <%= camelCaseName %>PublicPluginStart {
public start(core: CoreStart): <%= upperCamelCaseName %>PublicPluginStart {
return {}
}

public stop() {}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

export interface <%= camelCaseName %>PublicPluginSetup {}
export interface <%= camelCaseName %>PublicPluginStart {}
export interface <%= upperCamelCaseName %>PublicPluginSetup {
getGreeting: () => string;
}
export interface <%= upperCamelCaseName %>PublicPluginStart {}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PluginInitializerContext } from '<%= relRoot %>/src/core/server';
import { <%= camelCaseName %>ServerPlugin } from './plugin';
import { <%= upperCamelCaseName %>ServerPlugin } from './plugin';

export function plugin(initializerContext: PluginInitializerContext) {
return new <%= camelCaseName %>ServerPlugin(initializerContext);
return new <%= upperCamelCaseName %>ServerPlugin(initializerContext);
}

export { <%= camelCaseName %>ServerPlugin as Plugin };
export * from '../common';
export { <%= upperCamelCaseName %>ServerPlugin as Plugin };
lizozom marked this conversation as resolved.
Show resolved Hide resolved
export * from '../common';
lizozom marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@

import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '<%= relRoot %>/src/core/server';

export interface <%= camelCaseName %>PluginSetup {};
export interface <%= camelCaseName %>PluginStart {};
import {
<%= upperCamelCaseName %>PluginSetup,
<%= upperCamelCaseName %>PluginStart,
} from './types';

export class <%= camelCaseName %>ServerPlugin implements Plugin<<%= camelCaseName %>PluginSetup, <%= camelCaseName %>PluginStart> {
export class <%= upperCamelCaseName %>ServerPlugin implements Plugin<<%= upperCamelCaseName %>PluginSetup, <%= upperCamelCaseName %>PluginStart> {
constructor(initializerContext: PluginInitializerContext) {}
lizozom marked this conversation as resolved.
Show resolved Hide resolved

public setup(core: CoreSetup) {
const router = core.http.createRouter();

router.get(
{
path: '/api/<%= snakeCase(name) %>/example',
validate: false,
},
async (context, request, response) => {
return response.ok({
body: {
time: (new Date()).toISOString(),
}
});
}
);
return {};
}

@@ -18,4 +35,4 @@ export class <%= camelCaseName %>ServerPlugin implements Plugin<<%= camelCaseNam
public stop() {}
}

export { <%= camelCaseName %>ServerPlugin as Plugin };
export { <%= upperCamelCaseName %>ServerPlugin as Plugin };
lizozom marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export interface <%= upperCamelCaseName %>PluginSetup {};
export interface <%= upperCamelCaseName %>PluginStart {};