mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
@kbn/plugin-generator
minor cleanup (#189059)
## Summary Done while looking for https://github.com/elastic/kibana/issues/107773 - use `import type` modifier when possible - fix imports to use the `@kbn/plugin` format - remove references to CLI options that are no longer present
This commit is contained in:
parent
bd843dda3f
commit
6982321dbb
11 changed files with 14 additions and 79 deletions
|
@ -9,7 +9,6 @@
|
|||
import Path from 'path';
|
||||
import Fs from 'fs';
|
||||
|
||||
import execa from 'execa';
|
||||
import { REPO_ROOT } from '@kbn/repo-info';
|
||||
import { run } from '@kbn/dev-cli-runner';
|
||||
import { createFailError, createFlagError } from '@kbn/dev-cli-errors';
|
||||
|
@ -37,9 +36,7 @@ export function runCli() {
|
|||
};
|
||||
const answers = flags.yes ? getDefaultAnswers(overrides) : await askQuestions(overrides);
|
||||
|
||||
const outputDir = answers.internal
|
||||
? Path.resolve(answers.internalLocation, snakeCase(answers.name))
|
||||
: Path.resolve(REPO_ROOT, 'plugins', snakeCase(answers.name));
|
||||
const outputDir = Path.resolve(REPO_ROOT, 'plugins', snakeCase(answers.name));
|
||||
|
||||
if (Fs.existsSync(outputDir)) {
|
||||
throw createFailError(`Target output directory [${outputDir}] already exists`);
|
||||
|
@ -51,11 +48,6 @@ export function runCli() {
|
|||
answers,
|
||||
});
|
||||
|
||||
// init git repo in third party plugins
|
||||
if (!answers.internal) {
|
||||
await execa('git', ['init', outputDir]);
|
||||
}
|
||||
|
||||
log.success(
|
||||
`🎉\n\nYour plugin has been created in ${Path.relative(process.cwd(), outputDir)}\n`
|
||||
);
|
||||
|
|
|
@ -83,6 +83,7 @@ it('generates a plugin without UI', async () => {
|
|||
Array [
|
||||
<absolute path>/plugins/bar/.eslintrc.js,
|
||||
<absolute path>/plugins/bar/.gitignore,
|
||||
<absolute path>/plugins/bar/.i18nrc.json,
|
||||
<absolute path>/plugins/bar/common/index.ts,
|
||||
<absolute path>/plugins/bar/kibana.json,
|
||||
<absolute path>/plugins/bar/package.json,
|
||||
|
@ -91,6 +92,7 @@ it('generates a plugin without UI', async () => {
|
|||
<absolute path>/plugins/bar/server/plugin.ts,
|
||||
<absolute path>/plugins/bar/server/routes/index.ts,
|
||||
<absolute path>/plugins/bar/server/types.ts,
|
||||
<absolute path>/plugins/bar/translations/ja-JP.json,
|
||||
<absolute path>/plugins/bar/tsconfig.json,
|
||||
]
|
||||
`);
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import Path from 'path';
|
||||
|
||||
import { REPO_ROOT } from '@kbn/repo-info';
|
||||
|
||||
export interface PluginType {
|
||||
thirdParty: boolean;
|
||||
installDir: string;
|
||||
}
|
||||
|
||||
export const PLUGIN_TYPE_OPTIONS: Array<{ name: string; value: PluginType }> = [
|
||||
{
|
||||
name: 'Installable plugin',
|
||||
value: { thirdParty: true, installDir: Path.resolve(REPO_ROOT, 'plugins') },
|
||||
},
|
||||
{
|
||||
name: 'Kibana Example',
|
||||
value: { thirdParty: false, installDir: Path.resolve(REPO_ROOT, 'examples') },
|
||||
},
|
||||
{
|
||||
name: 'Kibana OSS',
|
||||
value: { thirdParty: false, installDir: Path.resolve(REPO_ROOT, 'src/plugins') },
|
||||
},
|
||||
{
|
||||
name: 'Kibana OSS Functional Testing',
|
||||
value: {
|
||||
thirdParty: false,
|
||||
installDir: Path.resolve(REPO_ROOT, 'test/plugin_functional/plugins'),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'X-Pack',
|
||||
value: { thirdParty: false, installDir: Path.resolve(REPO_ROOT, 'x-pack/plugins') },
|
||||
},
|
||||
{
|
||||
name: 'X-Pack Functional Testing',
|
||||
value: {
|
||||
thirdParty: false,
|
||||
installDir: Path.resolve(REPO_ROOT, 'x-pack/test/plugin_functional/plugins'),
|
||||
},
|
||||
},
|
||||
];
|
|
@ -58,9 +58,6 @@ export async function renderTemplates({
|
|||
const defaultTemplateData = {
|
||||
name: answers.name,
|
||||
|
||||
internalPlugin: !!answers.internal,
|
||||
thirdPartyPlugin: !answers.internal,
|
||||
|
||||
hasServer: !!answers.server,
|
||||
hasUi: !!answers.ui,
|
||||
|
||||
|
@ -85,12 +82,7 @@ export async function renderTemplates({
|
|||
// exclude files from the template based on selected options, patterns
|
||||
// are matched without the .ejs extension
|
||||
excludeFiles(
|
||||
([] as string[]).concat(
|
||||
answers.ui ? [] : 'public/**/*',
|
||||
answers.ui && !answers.internal ? [] : ['translations/**/*', '.i18nrc.json'],
|
||||
answers.server ? [] : 'server/**/*',
|
||||
!answers.internal ? [] : ['.eslintrc.js', 'tsconfig.json', 'package.json', '.gitignore']
|
||||
)
|
||||
([] as string[]).concat(answers.ui ? [] : 'public/**/*', answers.server ? [] : 'server/**/*')
|
||||
),
|
||||
|
||||
// render .ejs templates and rename to not use .ejs extension
|
||||
|
|
|
@ -8,7 +8,6 @@ A Kibana plugin
|
|||
|
||||
See the [kibana contributing guide](https://github.com/elastic/kibana/blob/main/CONTRIBUTING.md) for instructions setting up your development environment.
|
||||
|
||||
<% if (thirdPartyPlugin) { %>
|
||||
## Scripts
|
||||
<dl>
|
||||
<dt><code>yarn kbn bootstrap</code></dt>
|
||||
|
@ -20,4 +19,3 @@ See the [kibana contributing guide](https://github.com/elastic/kibana/blob/main/
|
|||
<dt><code>yarn plugin-helpers dev --watch</code></dt>
|
||||
<dd>Execute this to build your plugin ui browser side so Kibana could pick up when started in development</dd>
|
||||
</dl>
|
||||
<% } %>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { AppMountParameters, CoreStart } from '<%= importFromRoot('src/core/public') %>';
|
||||
import { AppPluginStartDependencies } from './types';
|
||||
import type { AppMountParameters, CoreStart } from '@kbn/core/public';
|
||||
import type { AppPluginStartDependencies } from './types';
|
||||
import { <%= upperCamelCase(name) %>App } from './components/app';
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { i18n } from '@kbn/i18n';
|
||||
import { AppMountParameters, CoreSetup, CoreStart, Plugin } from '<%= importFromRoot('src/core/public') %>';
|
||||
import { <%= upperCamelCase(name) %>PluginSetup, <%= upperCamelCase(name) %>PluginStart, AppPluginStartDependencies } from './types';
|
||||
import type { AppMountParameters, CoreSetup, CoreStart, Plugin } from '@kbn/core/public';
|
||||
import type { <%= upperCamelCase(name) %>PluginSetup, <%= upperCamelCase(name) %>PluginStart, AppPluginStartDependencies } from './types';
|
||||
import { PLUGIN_NAME } from '../common';
|
||||
|
||||
export class <%= upperCamelCase(name) %>Plugin
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { NavigationPublicPluginStart } from '<%= importFromRoot('src/plugins/navigation/public') %>';
|
||||
import type { NavigationPublicPluginStart } from '@kbn/navigation-plugin/public';
|
||||
|
||||
export interface <%= upperCamelCase(name) %>PluginSetup {
|
||||
getGreeting: () => string;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { PluginInitializerContext } from '<%= importFromRoot('src/core/server') %>';
|
||||
import type { PluginInitializerContext } from '@kbn/core/server';
|
||||
|
||||
// This exports static code and TypeScript types,
|
||||
// as well as, Kibana Platform `plugin()` initializer.
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import {
|
||||
import type {
|
||||
PluginInitializerContext,
|
||||
CoreSetup,
|
||||
CoreStart,
|
||||
Plugin,
|
||||
Logger
|
||||
} from '<%= importFromRoot('src/core/server') %>';
|
||||
} from '@kbn/core/server';
|
||||
|
||||
import {
|
||||
import type {
|
||||
<%= upperCamelCase(name) %>PluginSetup,
|
||||
<%= upperCamelCase(name) %>PluginStart
|
||||
} from './types';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { IRouter } from '<%= importFromRoot('src/core/server') %>';
|
||||
import type { IRouter } from '@kbn/core/server';
|
||||
|
||||
|
||||
export function defineRoutes(router: IRouter) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue