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
Show file tree
Hide file tree
Changes from 6 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe(`running the plugin-generator via 'node scripts/generate_plugin.js plug
expect(stats.isDirectory()).toBe(true);
});

// skipped until internationalization is re-introduced
it.skip(`should create an internationalization config file with a blank line appended to satisfy the parser`, async () => {
// Link to the error that happens when the blank line is not there:
// https://github.com/elastic/kibana/pull/45044#issuecomment-530092627
Expand All @@ -78,15 +79,6 @@ describe(`running the plugin-generator via 'node scripts/generate_plugin.js plug
});
});

it.skip(`'yarn test:server' should exit 0`, async () => {
await execa('yarn', ['test:server'], {
cwd: generatedPath,
env: {
DISABLE_JUNIT_REPORTER: '1',
},
});
});

it.skip(`'yarn build' should exit 0`, async () => {
await execa('yarn', ['build'], { cwd: generatedPath });
});
Expand All @@ -98,7 +90,7 @@ describe(`running the plugin-generator via 'node scripts/generate_plugin.js plug
beforeAll(es.start);
afterAll(es.stop);

it.skip(`'yarn start' should result in the spec plugin being initialized on kibana's stdout`, async () => {
it(`'yarn start' should result in the spec plugin being initialized on kibana's stdout`, async () => {
await withProcRunner(log, async proc => {
await proc.run('kibana', {
cmd: 'yarn',
Expand All @@ -109,7 +101,7 @@ describe(`running the plugin-generator via 'node scripts/generate_plugin.js plug
'--migrations.skip=true',
],
cwd: generatedPath,
wait: /ispec_plugin.+Status changed from uninitialized to green - Ready/,
wait: /ispec_plugin.+Setting up plugin/,
});
await proc.stop('kibana');
});
Expand Down
6 changes: 6 additions & 0 deletions packages/kbn-plugin-generator/sao_template/sao.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,19 @@ module.exports = function({ name, targetPath, isKibanaPlugin }) {
when: answers => answers.generateApp,
default: true,
},
generateEslint: {
type: 'confirm',
message: 'Should generate custom eslint file be used?',
lizozom marked this conversation as resolved.
Show resolved Hide resolved
default: !isKibanaPlugin,
},
},
filters: {
'public/**/index.scss': 'generateScss',
'public/**/*': 'generateApp',
'server/**/*': 'generateApi',
'translations/**/*': 'generateTranslations',
'.i18nrc.json': 'generateTranslations',
'eslintrc.js': 'generateEslint',
},
move: {
'eslintrc.js': '.eslintrc.js',
Expand Down
56 changes: 12 additions & 44 deletions packages/kbn-plugin-generator/sao_template/sao.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

const sao = require('sao');

const templatePkg = require('../package.json');

const template = {
fromPath: __dirname,
configOptions: {
Expand All @@ -32,29 +30,16 @@ function getFileContents(file) {
return file.contents.toString();
}

function getConfig(file) {
const contents = getFileContents(file).replace(/\r?\n/gm, '');
return contents.split('kibana.Plugin(')[1];
}

describe('plugin generator sao integration', () => {
test.skip('skips files when answering no', async () => {
test('skips files when answering no', async () => {
const res = await sao.mockPrompt(template, {
generateApp: false,
generateApi: false,
});

expect(res.fileList).not.toContain('public/app.js');
expect(res.fileList).not.toContain('public/__tests__/index.js');
expect(res.fileList).not.toContain('public/hack.js');
expect(res.fileList).not.toContain('server/routes/example.js');
expect(res.fileList).not.toContain('server/__tests__/index.js');

const uiExports = getConfig(res.files['index.js']);
expect(uiExports).not.toContain('app:');
expect(uiExports).not.toContain('hacks:');
expect(uiExports).not.toContain('init(server, options)');
expect(uiExports).not.toContain('registerFeature(');
expect(res.fileList).toContain('common/index.ts');
expect(res.fileList).not.toContain('public/index.ts');
expect(res.fileList).not.toContain('server/index.ts');
});

it('includes app when answering yes', async () => {
Expand All @@ -69,26 +54,21 @@ describe('plugin generator sao integration', () => {
expect(res.fileList).toContain('public/plugin.ts');
expect(res.fileList).toContain('public/types.ts');
expect(res.fileList).toContain('public/components/app.tsx');
expect(res.fileList).not.toContain('server/index.ts');
});

it.skip('includes server api when answering yes', async () => {
it('includes server api when answering yes', async () => {
const res = await sao.mockPrompt(template, {
generateApp: true,
generateApi: true,
});

// check output files
expect(res.fileList).toContain('public/app.js');
expect(res.fileList).toContain('public/__tests__/index.js');
expect(res.fileList).toContain('public/hack.js');
expect(res.fileList).toContain('server/routes/example.js');
expect(res.fileList).toContain('server/__tests__/index.js');

const uiExports = getConfig(res.files['index.js']);
expect(uiExports).toContain('app:');
expect(uiExports).toContain('hacks:');
expect(uiExports).toContain('init(server, options)');
expect(uiExports).toContain('registerFeature(');
expect(res.fileList).toContain('public/plugin.ts');
expect(res.fileList).toContain('server/plugin.ts');
expect(res.fileList).toContain('server/index.ts');
expect(res.fileList).toContain('server/types.ts');
expect(res.fileList).toContain('server/routes/index.ts');
});

it('plugin package has correct title', async () => {
Expand Down Expand Up @@ -125,17 +105,6 @@ describe('plugin generator sao integration', () => {
expect(pkg.version).toBe('v6.0.0');
});

it.skip('package has correct templateVersion', async () => {
const res = await sao.mockPrompt(template, {
kbnVersion: 'master',
});

const packageContents = getFileContents(res.files['kibana.json']);
const pkg = JSON.parse(packageContents);

expect(pkg.kibana.templateVersion).toBe(templatePkg.version);
});

it('sample app has correct values', async () => {
const res = await sao.mockPrompt(template, {
generateApp: true,
Expand All @@ -148,9 +117,8 @@ describe('plugin generator sao integration', () => {
expect(controllerLine).toContain('someFancyPlugin');
});

it.skip('includes dotfiles', async () => {
it('includes dotfiles', async () => {
const res = await sao.mockPrompt(template);
expect(res.files['.gitignore']).toBeTruthy();
expect(res.files['.eslintrc.js']).toBeTruthy();
});
});
4 changes: 2 additions & 2 deletions packages/kbn-plugin-generator/sao_template/template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

---

## development
## Development

See the [kibana contributing guide](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md) for instructions setting up your development environment. Once you have completed that, use the following yarn scripts.
See the [kibana contributing guide](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md) for instructions setting up your development environment.

Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const <%= upperCamelCaseName %>App = ({ basename, notifications, http, na
<p>
<FormattedMessage
id="<%= camelCase(name) %>.content"
defaultMessage="Look through the generated code and checkout the plugin development documentation."
defaultMessage="Look through the generated code and check out the plugin development documentation."
/>
</p>
<EuiHorizontalRule/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
import './index.scss';
<%_ } -%>

import { <%= upperCamelCaseName %>PublicPlugin } from './plugin';
import { <%= upperCamelCaseName %>Plugin } from './plugin';

/**
* This exports static code and TypeScript types,
* as well as, Kibana Platform `plugin()` initializer.
**/
export function plugin() {
return new <%= upperCamelCaseName %>PublicPlugin();
return new <%= upperCamelCaseName %>Plugin();
}

export * from '../common';
export * from './types';
export {
<%= upperCamelCaseName %>PluginSetup,
<%= upperCamelCaseName %>PluginStart,
} from './types';

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { i18n } from '@kbn/i18n';
import { AppMountParameters, CoreSetup, CoreStart, Plugin } from '<%= relRoot %>/src/core/public';
import { <%= upperCamelCaseName %>PublicPluginSetup, <%= upperCamelCaseName %>PublicPluginStart, AppPluginDependencies } from './types';
import { <%= upperCamelCaseName %>PluginSetup, <%= upperCamelCaseName %>PluginStart, AppPluginDependencies } from './types';
import { PLUGIN_NAME } from '../common';

export class <%= upperCamelCaseName %>PublicPlugin
implements Plugin<<%= upperCamelCaseName %>PublicPluginSetup, <%= upperCamelCaseName %>PublicPluginStart> {
export class <%= upperCamelCaseName %>Plugin
implements Plugin<<%= upperCamelCaseName %>PluginSetup, <%= upperCamelCaseName %>PluginStart> {

public setup(core: CoreSetup): <%= upperCamelCaseName %>PublicPluginSetup {
public setup(core: CoreSetup): <%= upperCamelCaseName %>PluginSetup {
// Register an application into the side navigation menu
core.application.register({
id: '<%= camelCase(name) %>',
Expand Down Expand Up @@ -34,7 +34,7 @@ export class <%= upperCamelCaseName %>PublicPlugin
};
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { NavigationPublicPluginStart } from '<%= relRoot %>/src/plugins/navigation/public';

export interface <%= upperCamelCaseName %>PublicPluginSetup {
export interface <%= upperCamelCaseName %>PluginSetup {
getGreeting: () => string;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface <%= upperCamelCaseName %>PublicPluginStart {}
export interface <%= upperCamelCaseName %>PluginStart {}

export interface AppPluginDependencies {
navigation: NavigationPublicPluginStart
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { PluginInitializerContext } from '<%= relRoot %>/src/core/server';
import { <%= upperCamelCaseName %>ServerPlugin } from './plugin';
import { <%= upperCamelCaseName %>Plugin } from './plugin';

export function plugin(initializerContext: PluginInitializerContext) {
return new <%= upperCamelCaseName %>ServerPlugin(initializerContext);
/**
* This exports static code and TypeScript types,
* as well as, Kibana Platform `plugin()` initializer.
**/
export function plugin(initializerContext: PluginInitializerContext) {
return new <%= upperCamelCaseName %>Plugin(initializerContext);
}

export { <%= upperCamelCaseName %>ServerPlugin as Plugin };
export * from '../common';
export {
<%= upperCamelCaseName %>PluginSetup,
<%= upperCamelCaseName %>PluginStart,
} from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PluginInitializerContext, CoreSetup, CoreStart, Plugin, Logger } from '
import { <%= upperCamelCaseName %>PluginSetup, <%= upperCamelCaseName %>PluginStart } from './types';
import { defineRoutes } from './routes';

export class <%= upperCamelCaseName %>ServerPlugin
export class <%= upperCamelCaseName %>Plugin
implements Plugin<<%= upperCamelCaseName %>PluginSetup, <%= upperCamelCaseName %>PluginStart> {
private readonly logger: Logger;

Expand All @@ -12,7 +12,7 @@ export class <%= upperCamelCaseName %>ServerPlugin
}

public setup(core: CoreSetup) {
this.logger.debug('<%= name %>: Ssetup');
this.logger.debug('<%= name %>: Setup');
const router = core.http.createRouter();

// Register server side APIs
Expand All @@ -28,5 +28,3 @@ export class <%= upperCamelCaseName %>ServerPlugin

public stop() {}
}

export { <%= upperCamelCaseName %>ServerPlugin as Plugin };