mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Log if no plugins are installed when listing plugins in cli (#97235)
This commit is contained in:
parent
41bf9e8427
commit
005745e649
2 changed files with 24 additions and 10 deletions
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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.",
|
||||
]
|
||||
`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue