Skip to content

Commit

Permalink
Rename plugin helpers (#37) (#63)
Browse files Browse the repository at this point in the history
* Add missing brace lost during merge conflict

* Rename kbn-plugin-helpers to osd-plugin-helpers (#37)

Signed-off-by: Bishoy Boktor <boktorbb@amazon.com>
  • Loading branch information
boktorbb authored Mar 5, 2021
1 parent 805f24f commit 19a5b2b
Show file tree
Hide file tree
Showing 19 changed files with 126 additions and 126 deletions.
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
# @kbn/plugin-helpers
# @osd/plugin-helpers

Just some helpers for kibana plugin devs.
Just some helpers for OpenSearch Dashboards plugin devs.

## Installation

You don't actually need to install the plugin helpers, they are automatically inherited from the Kibana project by building your plugin within the Kibana repo. To use the plugin helpers just create the needed npm scripts on your plugin's `package.json` (as exemplified below) which
You don't actually need to install the plugin helpers, they are automatically inherited from the OpenSearch Dashboards project by building your plugin within the OpenSearch Dashboards repo. To use the plugin helpers just create the needed npm scripts on your plugin's `package.json` (as exemplified below) which
is already the case if you use the new `node scripts/generate_plugin` script.

```json
{
"scripts" : {
"build": "yarn plugin-helpers build",
"plugin-helpers": "node ../../scripts/plugin_helpers",
"kbn": "node ../../scripts/kbn"
"osd": "node ../../scripts/osd"
}
}
```

This will make it easier to execute the `plugin-helpers` script from within your plugin repository.

```sh
yarn kbn bootstrap
yarn osd bootstrap
```

## Usage

This simple CLI has a build task that plugin devs can run from to easily package Kibana plugins.
This simple CLI has a build task that plugin devs can run from to easily package OpenSearch Dashboards plugins.

Previously you could also use that tool to start and test your plugin. Currently you can run
your plugin along with Kibana running `yarn start` in the Kibana repository root folder. Finally to test
your plugin along with OpenSearch Dashboards running `yarn start` in the OpenSearch Dashboards repository root folder. Finally to test
your plugin you should now configure and use your own tools.

```sh
Expand All @@ -39,16 +39,16 @@ $ plugin-helpers help
Commands:
build
Copies files from the source into a zip archive that can be distributed for
installation into production Kibana installs. The archive includes the non-
installation into production OpenSearch Dashboards installs. The archive includes the non-
development npm dependencies and builds itself using raw files in the source
directory so make sure they are clean/up to date. The resulting archive can
be found at:

build/{plugin.id}-{kibanaVersion}.zip
build/{plugin.id}-{opensearchDashboardsVersion}.zip

Options:
--skip-archive Don't create the zip file, just create the build/kibana directory
--kibana-version, -v Kibana version that the
--skip-archive Don't create the zip file, just create the build/opensearch-dashboards directory
--opensearch-dashboards-version, -v OpenSearch Dashboards version that the
Global options:
Expand All @@ -62,15 +62,15 @@ $ plugin-helpers help

## Versions

The plugins helpers in the Kibana repo are available for Kibana 6.3 and greater. Just checkout the branch of Kibana you want to build against and the plugin helpers should be up to date for that version of Kibana.
The plugins helpers in the OpenSearch Dashboards repo are available for OpenSearch Dashboards 6.3 and greater. Just checkout the branch of OpenSearch Dashboards you want to build against and the plugin helpers should be up to date for that version of OpenSearch Dashboards.

When you're targeting versions before Kibana 6.3, use the `@elastic/plugin-helpers` from npm. See the [versions](https://github.com/elastic/kibana-plugin-helpers#versions) section of the [`@elastic/plugin-helpers` readme](https://github.com/elastic/kibana-plugin-helpers) for information about version compatibility.
When you're targeting versions before OpenSearch Dashboards 6.3, use the `@elastic/plugin-helpers` from npm. See the [versions](https://github.com/elastic/kibana-plugin-helpers#versions) section of the [`@elastic/plugin-helpers` readme](https://github.com/elastic/kibana-plugin-helpers) for information about version compatibility.

## Configuration

`plugin-helpers` accepts a number of settings, which can be specified at runtime, or included in a `.kibana-plugin-helpers.json` file if you'd like to bundle those settings with your project.
`plugin-helpers` accepts a number of settings, which can be specified at runtime, or included in a `.opensearch-dashboards-plugin-helpers.json` file if you'd like to bundle those settings with your project.

It will also observe a `.kibana-plugin-helpers.dev.json`, much like Kibana does, which we encourage you to add to your `.gitignore` file and use for local settings that you don't intend to share. These "dev" settings will override any settings in the normal json config.
It will also observe a `.opensearch-dashboards-plugin-helpers.dev.json`, much like OpenSearch Dashboards does, which we encourage you to add to your `.gitignore` file and use for local settings that you don't intend to share. These "dev" settings will override any settings in the normal json config.

All configuration setting listed below can simply can be included in the json config files. If you intend to inline the command, you will need to convert the setting to snake case (ie. `skipArchive` becomes `--skip-archive`).

Expand All @@ -80,19 +80,19 @@ All configuration setting listed below can simply can be included in the json co

Setting | Description
------- | -----------
`serverSourcePatterns` | Defines the files that are built with babel and written to your distributable for your server plugin. It is ignored if `kibana.json` has none `server: true` setting defined.
`serverSourcePatterns` | Defines the files that are built with babel and written to your distributable for your server plugin. It is ignored if `opensearch_dashboards.json` has none `server: true` setting defined.
`skipArchive` | Don't create the zip file, leave the build path alone
`skipInstallDependencies` | Don't install dependencies defined in package.json into build output
`kibanaVersion` | Kibana version for the build output (added to package.json)
`opensearchDashboardsVersion` | OpenSearch Dashboards version for the build output (added to package.json)

## TypeScript support

Plugin code can be written in [TypeScript](http://www.typescriptlang.org/) if desired. To enable TypeScript support create a `tsconfig.json` file at the root of your plugin that looks something like this:

```js
{
// extend Kibana's tsconfig, or use your own settings
"extends": "../../kibana/tsconfig.json",
// extend OpenSearch Dashboards's tsconfig, or use your own settings
"extends": "../../opensearch-dashboards/tsconfig.json",

// tell the TypeScript compiler where to find your source files
"include": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"name": "@kbn/plugin-helpers",
"name": "@osd/plugin-helpers",
"version": "1.0.0",
"private": true,
"description": "Just some helpers for kibana plugin devs.",
"description": "Just some helpers for OpenSearch Dashboards plugin devs.",
"license": "Apache-2.0",
"kibana": {
"opensearchDashboards": {
"devOnly": true
},
"main": "target/index.js",
"bin": {
"plugin-helpers": "bin/plugin-helpers.js"
},
"scripts": {
"kbn:bootstrap": "rm -rf target && tsc",
"kbn:watch": "tsc --watch"
"osd:bootstrap": "rm -rf target && tsc",
"osd:watch": "tsc --watch"
},
"dependencies": {
"@kbn/dev-utils": "1.0.0",
"@kbn/optimizer": "1.0.0",
"@osd/dev-utils": "1.0.0",
"@osd/optimizer": "1.0.0",
"del": "^5.1.0",
"execa": "^4.0.2",
"gulp-zip": "^5.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* under the License.
*/

import { ToolingLog } from '@kbn/dev-utils';
import { ToolingLog } from '@osd/dev-utils';

import { Plugin } from './load_kibana_platform_plugin';
import { Plugin } from './load_opensearch_dashboards_platform_plugin';
import { Config } from './config';

export interface BuildContext {
Expand All @@ -28,5 +28,5 @@ export interface BuildContext {
config: Config;
sourceDir: string;
buildDir: string;
kibanaVersion: string;
opensearchDashboardsVersion: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import Path from 'path';

import semver from 'semver';
import { RunWithCommands, createFlagError, createFailError } from '@kbn/dev-utils';
import { RunWithCommands, createFlagError, createFailError } from '@osd/dev-utils';

import { findKibanaJson } from './find_kibana_json';
import { loadKibanaPlatformPlugin } from './load_kibana_platform_plugin';
import { findOpenSearchDashboardsJson } from './find_opensearch_dashboards_json';
import { loadOpenSearchDashboardsPlatformPlugin } from './load_opensearch_dashboards_platform_plugin';
import * as Tasks from './tasks';
import { BuildContext } from './build_context';
import { resolveKibanaVersion } from './resolve_kibana_version';
import { resolveOpenSearchDashboardsVersion } from './resolve_opensearch_dashboards_version';
import { loadConfig } from './config';

export function runCli() {
Expand All @@ -37,69 +37,69 @@ export function runCli() {
name: 'build',
description: `
Copies files from the source into a zip archive that can be distributed for
installation into production Kibana installs. The archive includes the non-
installation into production OpenSearch Dashboards installs. The archive includes the non-
development npm dependencies and builds itself using raw files in the source
directory so make sure they are clean/up to date. The resulting archive can
be found at:
build/{plugin.id}-{kibanaVersion}.zip
build/{plugin.id}-{opensearchDashboardsVersion}.zip
`,
flags: {
boolean: ['skip-archive'],
string: ['kibana-version'],
string: ['opensearch-dashboards-version'],
alias: {
k: 'kibana-version',
k: 'opensearch-dashboards-version',
},
help: `
--skip-archive Don't create the zip file, just create the build/kibana directory
--kibana-version, -v Kibana version that the
--skip-archive Don't create the zip file, just create the build/opensearch-dashboards directory
--opensearch-dashboards-version, -v OpenSearch version that the
`,
},
async run({ log, flags }) {
const versionFlag = flags['kibana-version'];
const versionFlag = flags['opensearch-dashboards-version'];
if (versionFlag !== undefined && typeof versionFlag !== 'string') {
throw createFlagError('expected a single --kibana-version flag');
throw createFlagError('expected a single --opensearch-dashboards-version flag');
}

const skipArchive = flags['skip-archive'];
if (skipArchive !== undefined && typeof skipArchive !== 'boolean') {
throw createFlagError('expected a single --skip-archive flag');
}

const pluginDir = await findKibanaJson(process.cwd());
const pluginDir = await findOpenSearchDashboardsJson(process.cwd());
if (!pluginDir) {
throw createFailError(
`Unable to find Kibana Platform plugin in [${process.cwd()}] or any of its parent directories. Has it been migrated properly? Does it have a kibana.json file?`
`Unable to find OpenSearch Dashboards Platform plugin in [${process.cwd()}] or any of its parent directories. Has it been migrated properly? Does it have a opensearch_dashboards.json file?`
);
}

const plugin = loadKibanaPlatformPlugin(pluginDir);
const plugin = loadOpenSearchDashboardsPlatformPlugin(pluginDir);
const config = await loadConfig(log, plugin);
const kibanaVersion = await resolveKibanaVersion(versionFlag, plugin);
const opensearchDashboardsVersion = await resolveOpenSearchDashboardsVersion(versionFlag, plugin);

if (semver.satisfies(kibanaVersion, '<7.9')) {
if (semver.satisfies(opensearchDashboardsVersion, '<7.9')) {
log.error(
'These tools are not designed to work with version before 7.9, please checkout an earlier version of Kibana to build your plugin'
'These tools are not designed to work with version before 7.9, please checkout an earlier version of OpenSearch Dashboards to build your plugin'
);
process.exit(1);
}
if (semver.satisfies(kibanaVersion, '~7.9.0')) {
if (semver.satisfies(opensearchDashboardsVersion, '~7.9.0')) {
log.warning(
'These tools might work with 7.9 versions, but there are known workarounds required. See https://github.com/elastic/kibana/issues/82466 for more info'
);
}

const sourceDir = plugin.directory;
const buildDir = Path.resolve(plugin.directory, 'build/kibana', plugin.manifest.id);
const buildDir = Path.resolve(plugin.directory, 'build/opensearch-dashboards', plugin.manifest.id);

const context: BuildContext = {
log,
plugin,
config,
sourceDir,
buildDir,
kibanaVersion,
opensearchDashboardsVersion,
};

await Tasks.initTargets(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import Path from 'path';

import loadJsonFile from 'load-json-file';

import { ToolingLog } from '@kbn/dev-utils';
import { Plugin } from './load_kibana_platform_plugin';
import { ToolingLog } from '@osd/dev-utils';
import { Plugin } from './load_opensearch_dashboards_platform_plugin';

export interface Config {
skipInstallDependencies: boolean;
Expand All @@ -34,7 +34,7 @@ const isArrayOfStrings = (v: any): v is string[] =>

export async function loadConfig(log: ToolingLog, plugin: Plugin): Promise<Config> {
try {
const path = Path.resolve(plugin.directory, '.kibana-plugin-helpers.json');
const path = Path.resolve(plugin.directory, '.opensearch-dashboards-plugin-helpers.json');
const file = await loadJsonFile(path);

if (!(typeof file === 'object' && file && !Array.isArray(file))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { promisify } from 'util';

const existsAsync = promisify(Fs.exists);

export async function findKibanaJson(directory: string): Promise<string | undefined> {
if (await existsAsync(Path.resolve(directory, 'kibana.json'))) {
export async function findOpenSearchDashboardsJson(directory: string): Promise<string | undefined> {
if (await existsAsync(Path.resolve(directory, 'opensearch_dashboards.json'))) {
return directory;
}

Expand All @@ -33,5 +33,5 @@ export async function findKibanaJson(directory: string): Promise<string | undefi
return undefined;
}

return findKibanaJson(parent);
return findOpenSearchDashboardsJson(parent);
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ import Path from 'path';
import Fs from 'fs';

import execa from 'execa';
import { REPO_ROOT } from '@kbn/utils';
import { createStripAnsiSerializer, createReplaceSerializer } from '@kbn/dev-utils';
import { REPO_ROOT } from '@osd/utils';
import { createStripAnsiSerializer, createReplaceSerializer } from '@osd/dev-utils';
import extract from 'extract-zip';
import del from 'del';
import globby from 'globby';
import loadJsonFile from 'load-json-file';

const KIBANA_VERSION = '7.9.0';
const OPENSEARCH_DASHBOARDS_VERSION = '7.9.0';
const PLUGIN_DIR = Path.resolve(REPO_ROOT, 'plugins/foo_test_plugin');
const PLUGIN_BUILD_DIR = Path.resolve(PLUGIN_DIR, 'build');
const PLUGIN_ARCHIVE = Path.resolve(PLUGIN_BUILD_DIR, `fooTestPlugin-${KIBANA_VERSION}.zip`);
const PLUGIN_ARCHIVE = Path.resolve(PLUGIN_BUILD_DIR, `fooTestPlugin-${OPENSEARCH_DASHBOARDS_VERSION}.zip`);
const TMP_DIR = Path.resolve(__dirname, '__tmp__');

expect.addSnapshotSerializer(createReplaceSerializer(/[\d\.]+ sec/g, '<time>'));
Expand Down Expand Up @@ -65,7 +65,7 @@ it('builds a generated plugin into a viable archive', async () => {

const buildProc = await execa(
process.execPath,
['../../scripts/plugin_helpers', 'build', '--kibana-version', KIBANA_VERSION],
['../../scripts/plugin_helpers', 'build', '--opensearch-dashboards-version', OPENSEARCH_DASHBOARDS_VERSION],
{
cwd: PLUGIN_DIR,
all: true,
Expand All @@ -75,7 +75,7 @@ it('builds a generated plugin into a viable archive', async () => {
expect(buildProc.all).toMatchInlineSnapshot(`
" warn These tools might work with 7.9 versions, but there are known workarounds required. See https://github.com/elastic/kibana/issues/82466 for more info
info deleting the build and target directories
info running @kbn/optimizer
info running @osd/optimizer
│ info initialized, 0 bundles cached
│ info starting worker [1 bundle]
│ warn worker stderr Browserslist: caniuse-lite is outdated. Please run:
Expand All @@ -87,36 +87,36 @@ it('builds a generated plugin into a viable archive', async () => {
info compressing plugin into [fooTestPlugin-7.9.0.zip]"
`);

await extract(PLUGIN_ARCHIVE, { dir: TMP_DIR }, () => {});
await extract(PLUGIN_ARCHIVE, { dir: TMP_DIR }, () => { });

const files = await globby(['**/*'], { cwd: TMP_DIR });
files.sort((a, b) => a.localeCompare(b));

expect(files).toMatchInlineSnapshot(`
Array [
"kibana/fooTestPlugin/common/index.js",
"kibana/fooTestPlugin/kibana.json",
"kibana/fooTestPlugin/package.json",
"kibana/fooTestPlugin/server/index.js",
"kibana/fooTestPlugin/server/plugin.js",
"kibana/fooTestPlugin/server/routes/index.js",
"kibana/fooTestPlugin/server/types.js",
"kibana/fooTestPlugin/target/public/fooTestPlugin.chunk.1.js",
"kibana/fooTestPlugin/target/public/fooTestPlugin.chunk.1.js.br",
"kibana/fooTestPlugin/target/public/fooTestPlugin.chunk.1.js.gz",
"kibana/fooTestPlugin/target/public/fooTestPlugin.plugin.js",
"kibana/fooTestPlugin/target/public/fooTestPlugin.plugin.js.br",
"kibana/fooTestPlugin/target/public/fooTestPlugin.plugin.js.gz",
"kibana/fooTestPlugin/translations/ja-JP.json",
"kibana/fooTestPlugin/tsconfig.json",
"opensearch-dashboards/fooTestPlugin/common/index.js",
"opensearch-dashboards/fooTestPlugin/opensearch_dashboards.json",
"opensearch-dashboards/fooTestPlugin/package.json",
"opensearch-dashboards/fooTestPlugin/server/index.js",
"opensearch-dashboards/fooTestPlugin/server/plugin.js",
"opensearch-dashboards/fooTestPlugin/server/routes/index.js",
"opensearch-dashboards/fooTestPlugin/server/types.js",
"opensearch-dashboards/fooTestPlugin/target/public/fooTestPlugin.chunk.1.js",
"opensearch-dashboards/fooTestPlugin/target/public/fooTestPlugin.chunk.1.js.br",
"opensearch-dashboards/fooTestPlugin/target/public/fooTestPlugin.chunk.1.js.gz",
"opensearch-dashboards/fooTestPlugin/target/public/fooTestPlugin.plugin.js",
"opensearch-dashboards/fooTestPlugin/target/public/fooTestPlugin.plugin.js.br",
"opensearch-dashboards/fooTestPlugin/target/public/fooTestPlugin.plugin.js.gz",
"opensearch-dashboards/fooTestPlugin/translations/ja-JP.json",
"opensearch-dashboards/fooTestPlugin/tsconfig.json",
]
`);

expect(loadJsonFile.sync(Path.resolve(TMP_DIR, 'kibana', 'fooTestPlugin', 'kibana.json')))
expect(loadJsonFile.sync(Path.resolve(TMP_DIR, 'opensearch-dashboards', 'fooTestPlugin', 'opensearch_dashboards.json')))
.toMatchInlineSnapshot(`
Object {
"id": "fooTestPlugin",
"kibanaVersion": "7.9.0",
"opensearchDashboardsVersion": "7.9.0",
"optionalPlugins": Array [],
"requiredPlugins": Array [
"navigation",
Expand Down
Loading

0 comments on commit 19a5b2b

Please sign in to comment.