Log if no plugins are installed when listing plugins in cli (#97235)

This commit is contained in:
Thomas Watson 2021-04-15 15:58:58 +02:00 committed by GitHub
parent 41bf9e8427
commit 005745e649
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 10 deletions

View file

@ -10,17 +10,22 @@ import { statSync, readdirSync, readFileSync } from 'fs';
import { join } from 'path';
export function list(pluginDir, logger) {
readdirSync(pluginDir).forEach((name) => {
const stat = statSync(join(pluginDir, name));
const plugins = readdirSync(pluginDir)
.map((name) => [name, statSync(join(pluginDir, name))])
.filter(([name, stat]) => stat.isDirectory() && name[0] !== '.');
if (stat.isDirectory() && name[0] !== '.') {
try {
const packagePath = join(pluginDir, name, 'kibana.json');
const pkg = JSON.parse(readFileSync(packagePath, 'utf8'));
logger.log(pkg.id + '@' + pkg.version);
} catch (e) {
throw new Error('Unable to read kibana.json file for plugin ' + name);
}
if (plugins.length === 0) {
logger.log('No plugins installed.');
return;
}
plugins.forEach(([name]) => {
try {
const packagePath = join(pluginDir, name, 'kibana.json');
const pkg = JSON.parse(readFileSync(packagePath, 'utf8'));
logger.log(pkg.id + '@' + pkg.version);
} catch (e) {
throw new Error('Unable to read kibana.json file for plugin ' + name);
}
});
}

View file

@ -91,5 +91,14 @@ describe('kibana cli', function () {
`"Unable to read kibana.json file for plugin invalid-plugin"`
);
});
it('show message if no plugins are installed', function () {
list(pluginDir, logger);
expect(logger.messages).toMatchInlineSnapshot(`
Array [
"log: No plugins installed.",
]
`);
});
});
});