mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Display plugins versions
This is useful to determine if a plugin needs to be updated when using deployment automation solution (like Ansible)
This commit is contained in:
parent
173a217a9d
commit
2c1d76594e
2 changed files with 55 additions and 22 deletions
|
@ -5,7 +5,14 @@ import mkdirp from 'mkdirp';
|
|||
import Logger from '../../lib/logger';
|
||||
import list from '../list';
|
||||
import { join } from 'path';
|
||||
import { writeFileSync } from 'fs';
|
||||
import { writeFileSync, appendFileSync } from 'fs';
|
||||
|
||||
|
||||
function createPlugin(name, version, pluginBaseDir) {
|
||||
const pluginDir = join(pluginBaseDir, name);
|
||||
mkdirp.sync(pluginDir);
|
||||
appendFileSync(join(pluginDir, 'package.json'), '{"version": "' + version + '"}');
|
||||
}
|
||||
|
||||
describe('kibana cli', function () {
|
||||
|
||||
|
@ -33,41 +40,61 @@ describe('kibana cli', function () {
|
|||
});
|
||||
|
||||
it('list all of the folders in the plugin folder', function () {
|
||||
mkdirp.sync(join(pluginDir, 'plugin1'));
|
||||
mkdirp.sync(join(pluginDir, 'plugin2'));
|
||||
mkdirp.sync(join(pluginDir, 'plugin3'));
|
||||
createPlugin('plugin1', '5.0.0-alpha2', pluginDir);
|
||||
createPlugin('plugin2', '3.2.1', pluginDir);
|
||||
createPlugin('plugin3', '1.2.3', pluginDir);
|
||||
|
||||
list(settings, logger);
|
||||
|
||||
expect(logger.log.calledWith('plugin1')).to.be(true);
|
||||
expect(logger.log.calledWith('plugin2')).to.be(true);
|
||||
expect(logger.log.calledWith('plugin3')).to.be(true);
|
||||
expect(logger.log.calledWith('plugin1@5.0.0-alpha2')).to.be(true);
|
||||
expect(logger.log.calledWith('plugin2@3.2.1')).to.be(true);
|
||||
expect(logger.log.calledWith('plugin3@1.2.3')).to.be(true);
|
||||
});
|
||||
|
||||
it('ignore folders that start with a period', function () {
|
||||
mkdirp.sync(join(pluginDir, '.foo'));
|
||||
mkdirp.sync(join(pluginDir, 'plugin1'));
|
||||
mkdirp.sync(join(pluginDir, 'plugin2'));
|
||||
mkdirp.sync(join(pluginDir, 'plugin3'));
|
||||
mkdirp.sync(join(pluginDir, '.bar'));
|
||||
createPlugin('.foo', '1.0.0', pluginDir);
|
||||
createPlugin('plugin1', '5.0.0-alpha2', pluginDir);
|
||||
createPlugin('plugin2', '3.2.1', pluginDir);
|
||||
createPlugin('plugin3', '1.2.3', pluginDir);
|
||||
createPlugin('.bar', '1.0.0', pluginDir);
|
||||
|
||||
list(settings, logger);
|
||||
|
||||
expect(logger.log.calledWith('.foo')).to.be(false);
|
||||
expect(logger.log.calledWith('.bar')).to.be(false);
|
||||
expect(logger.log.calledWith('.foo@1.0.0')).to.be(false);
|
||||
expect(logger.log.calledWith('.bar@1.0.0')).to.be(false);
|
||||
});
|
||||
|
||||
it('list should only list folders', function () {
|
||||
mkdirp.sync(join(pluginDir, 'plugin1'));
|
||||
mkdirp.sync(join(pluginDir, 'plugin2'));
|
||||
mkdirp.sync(join(pluginDir, 'plugin3'));
|
||||
createPlugin('plugin1', '1.0.0', pluginDir);
|
||||
createPlugin('plugin2', '1.0.0', pluginDir);
|
||||
createPlugin('plugin3', '1.0.0', pluginDir);
|
||||
writeFileSync(join(pluginDir, 'plugin4'), 'This is a file, and not a folder.');
|
||||
|
||||
list(settings, logger);
|
||||
|
||||
expect(logger.log.calledWith('plugin1')).to.be(true);
|
||||
expect(logger.log.calledWith('plugin2')).to.be(true);
|
||||
expect(logger.log.calledWith('plugin3')).to.be(true);
|
||||
expect(logger.log.calledWith('plugin1@1.0.0')).to.be(true);
|
||||
expect(logger.log.calledWith('plugin2@1.0.0')).to.be(true);
|
||||
expect(logger.log.calledWith('plugin3@1.0.0')).to.be(true);
|
||||
});
|
||||
|
||||
it('list should throw an exception if a plugin does not have a package.json', function () {
|
||||
createPlugin('plugin1', '1.0.0', pluginDir);
|
||||
mkdirp.sync(join(pluginDir, 'empty-plugin'));
|
||||
|
||||
expect(function () {
|
||||
list(settings, logger);
|
||||
}).to.throwError('Unable to read package.json file for plugin empty-plugin');
|
||||
});
|
||||
|
||||
it('list should throw an exception if a plugin have an empty package.json', function () {
|
||||
createPlugin('plugin1', '1.0.0', pluginDir);
|
||||
const invalidPluginDir = join(pluginDir, 'invalid-plugin');
|
||||
mkdirp.sync(invalidPluginDir);
|
||||
appendFileSync(join(invalidPluginDir, 'package.json'), '');
|
||||
|
||||
expect(function () {
|
||||
list(settings, logger);
|
||||
}).to.throwError('Unable to read package.json file for plugin invalid-plugin');
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { statSync, readdirSync } from 'fs';
|
||||
import { statSync, readdirSync, readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
export default function list(settings, logger) {
|
||||
|
@ -7,7 +7,13 @@ export default function list(settings, logger) {
|
|||
const stat = statSync(join(settings.pluginDir, filename));
|
||||
|
||||
if (stat.isDirectory() && filename[0] !== '.') {
|
||||
logger.log(filename);
|
||||
try {
|
||||
const packagePath = join(settings.pluginDir, filename, 'package.json');
|
||||
const { version } = JSON.parse(readFileSync(packagePath, 'utf8'));
|
||||
logger.log(filename + '@' + version);
|
||||
} catch (e) {
|
||||
throw new Error('Unable to read package.json file for plugin ' + filename);
|
||||
}
|
||||
}
|
||||
});
|
||||
logger.log(''); //intentional blank line for aesthetics
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue