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

[kibana-plugin CLI][master] add optimize task and skip-optimize option on install task #14991

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions src/cli_plugin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { pkg } from '../utils';
import Command from '../cli/command';
import listCommand from './list';
import installCommand from './install';
import optimizeCommand from './optimize';
import removeCommand from './remove';

const argv = process.env.kbnWorkerArgv ? JSON.parse(process.env.kbnWorkerArgv) : process.argv.slice();
Expand All @@ -17,6 +18,7 @@ program

listCommand(program);
installCommand(program);
optimizeCommand(program);
removeCommand(program);

program
Expand Down
5 changes: 5 additions & 0 deletions src/cli_plugin/install/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export default function pluginInstall(program) {
'path to the directory where plugins are stored (DEPRECATED, known to not work for all plugins)',
fromRoot('plugins')
)
.option(
'--skip-optimize',
'avoid the mandatory optimization after each plugin installation. \n' +
'Require a manual "kibana-plugin optimize" command to update bundle and reload the available plugins list'
)
.description('install a plugin',
`Common examples:
install x-pack
Expand Down
7 changes: 7 additions & 0 deletions src/cli_plugin/install/kibana.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ export function existingInstall(settings, logger) {
}

export async function rebuildCache(settings, logger) {

if (settings.skipOptimize) {
logger.log('Skip optimize task due to given settings (--skip-optimize). ' +
'Remember to run a dedicated optimization task before starting Kibana !');
return;
}

logger.log('Optimizing and caching browser bundles...');
const serverConfig = _.merge(
readYamlConfig(settings.config),
Expand Down
3 changes: 2 additions & 1 deletion src/cli_plugin/install/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export function parse(command, options, kbnPackage) {
config: options.config || '',
plugin: command,
version: kbnPackage.version,
pluginDir: options.pluginDir || ''
pluginDir: options.pluginDir || '',
skipOptimize: options.skipOptimize || false
};

settings.urls = generateUrls(settings);
Expand Down
41 changes: 41 additions & 0 deletions src/cli_plugin/optimize/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import expect from 'expect.js';
import sinon from 'sinon';
import index from '../index';

describe('kibana cli', function () {

describe('plugin installer', function () {

describe('commander options', function () {

const program = {
command: function () { return program; },
description: function () { return program; },
option: function () { return program; },
action: function () { return program; }
};

it('should define the command', function () {
sinon.spy(program, 'command');

index(program);
expect(program.command.calledWith('optimize')).to.be(true);

program.command.restore();
});

it('should define the description', function () {
sinon.spy(program, 'description');

index(program);
expect(program.description.calledWith('force the optimization for all plugins')).to.be(true);

program.description.restore();
});


});

});

});
42 changes: 42 additions & 0 deletions src/cli_plugin/optimize/__tests__/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import expect from 'expect.js';
import { fromRoot } from '../../../utils';
import { parse } from '../settings';

describe('kibana cli', function () {

describe('plugin optimizer', function () {

describe('command line option parsing', function () {

describe('parse function', function () {

let command;
const options = {};
beforeEach(function () {
command = { pluginDir: fromRoot('plugins') };
});

describe('pluginDir option', function () {

it('should default to plugins', function () {
const settings = parse(command, options);

expect(settings.pluginDir).to.be(fromRoot('plugins'));
});

it('should set settings.config property', function () {
command.pluginDir = 'foo bar baz';
const settings = parse(command, options);

expect(settings.pluginDir).to.be('foo bar baz');
});

});

});

});

});

});
35 changes: 35 additions & 0 deletions src/cli_plugin/optimize/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { fromRoot } from '../../utils';
import optimize from './optimize';
import Logger from '../lib/logger';
import { parse } from './settings';
import logWarnings from '../lib/log_warnings';

function processCommand(command) {
let settings;
try {
settings = parse(command);

} catch (ex) {
//The logger has not yet been initialized.
console.error(ex.message);
process.exit(64); // eslint-disable-line no-process-exit
}

const logger = new Logger(settings);
logWarnings(settings, logger);
optimize(settings, logger);
}

export default function pluginOptimize(program) {
program
.command('optimize')
.option('-q, --quiet', 'disable all process messaging except errors')
.option('-s, --silent', 'disable all process messaging')
.option(
'-d, --plugin-dir <path>',
'path to the directory where plugins are stored',
fromRoot('plugins')
)
.description('force the optimization for all plugins')
.action(processCommand);
}
16 changes: 16 additions & 0 deletions src/cli_plugin/optimize/optimize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { cleanArtifacts } from '../install/cleanup';
import { rebuildCache } from '../install/kibana';

export default async function optimize(settings, logger) {
try {
logger.log('Start stand-alone plugins optimization');

await rebuildCache(settings, logger);

logger.log('Plugin optimization complete');
} catch (err) {
logger.error(`Plugin optimization was unsuccessful due to error "${err.message}"`);
cleanArtifacts(settings);
process.exit(70); // eslint-disable-line no-process-exit
}
}
10 changes: 10 additions & 0 deletions src/cli_plugin/optimize/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function parse(command) {

const settings = {
quiet: command.quiet || false,
silent: command.silent || false,
pluginDir: command.pluginDir || ''
};

return settings;
}