-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02a46b9
commit 6ace3b1
Showing
13 changed files
with
294 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { Flags } from '@kbn/dev-cli-runner'; | ||
import { findTeamPlugins } from '@kbn/docs-utils'; | ||
import { ToolingLog } from '@kbn/tooling-log'; | ||
import { Project } from 'ts-morph'; | ||
import { getPlugin } from '../lib'; | ||
import { displayDependencyCheck } from './display_dependency_check'; | ||
|
||
export const checkDependencies = (flags: Flags, log: ToolingLog) => { | ||
const checkPlugin = (name: string) => { | ||
const plugin = getPlugin(name, log); | ||
|
||
if (!plugin) { | ||
log.error(`Cannot find plugin ${name}`); | ||
return; | ||
} | ||
|
||
const project = new Project({ | ||
tsConfigFilePath: `${plugin.directory}/tsconfig.json`, | ||
}); | ||
|
||
displayDependencyCheck(project, plugin, log); | ||
}; | ||
|
||
const pluginName = flags.plugin && typeof flags.plugin === 'string' ? flags.plugin : null; | ||
const teamName = flags.team && typeof flags.team === 'string' ? flags.team : null; | ||
|
||
if ((!pluginName && !teamName) || (pluginName && teamName)) { | ||
log.error(`Must specify plugin or team name.`); | ||
return; | ||
} | ||
|
||
if (pluginName) { | ||
checkPlugin(pluginName); | ||
} | ||
|
||
if (teamName) { | ||
const plugins = findTeamPlugins(teamName); | ||
|
||
plugins.forEach((plugin) => { | ||
checkPlugin(plugin.manifest.id); | ||
}); | ||
} | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ToolingLog } from '@kbn/tooling-log'; | ||
|
||
import { getAllPlugins } from './lib'; | ||
|
||
interface Dependents { | ||
required: readonly string[]; | ||
optional: readonly string[]; | ||
bundles?: readonly string[]; | ||
} | ||
|
||
export const findDependents = (plugin: string, log: ToolingLog): Dependents => { | ||
log.info(`Finding dependents for ${plugin}`); | ||
const plugins = getAllPlugins(log); | ||
const required: string[] = []; | ||
const optional: string[] = []; | ||
const bundles: string[] = []; | ||
|
||
plugins.forEach((p) => { | ||
const manifest = p.manifest; | ||
|
||
if (manifest.requiredPlugins?.includes(plugin)) { | ||
required.push(manifest.id); | ||
} | ||
|
||
if (manifest.optionalPlugins?.includes(plugin)) { | ||
optional.push(manifest.id); | ||
} | ||
|
||
if (manifest.requiredBundles?.includes(plugin)) { | ||
bundles.push(manifest.id); | ||
} | ||
}); | ||
|
||
if (required.length === 0 && optional.length === 0 && bundles.length === 0) { | ||
log.info(`No plugins depend on ${plugin}`); | ||
} | ||
|
||
if (required.length > 0) { | ||
log.info(`REQUIRED BY ${required.length}:\n${required.join('\n')}\n`); | ||
} | ||
|
||
if (optional.length > 0) { | ||
log.info(`OPTIONAL FOR ${optional.length}:\n${optional.join('\n')}\n`); | ||
} | ||
|
||
if (bundles.length > 0) { | ||
log.info(`BUNDLE FOR ${bundles.length}:\n${bundles.join('\n')}\n`); | ||
} | ||
|
||
return { | ||
required, | ||
optional, | ||
bundles, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { findPlugins } from '@kbn/docs-utils'; | ||
import { ToolingLog } from '@kbn/tooling-log'; | ||
|
||
/** | ||
* Utility method for finding and logging information about all plugins. | ||
*/ | ||
export const getAllPlugins = (log: ToolingLog) => { | ||
const plugins = findPlugins().filter((plugin) => plugin.isPlugin); | ||
log.info(`Found ${plugins.length} plugins.`); | ||
log.debug('Found plugins:', plugins); | ||
return plugins; | ||
}; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { getPlugin } from './get_plugin'; | ||
export { getPluginClasses } from './get_plugin_classes'; | ||
export { getAllPlugins } from './get_all_plugins'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { MultiBar, Presets } from 'cli-progress'; | ||
|
||
import { ToolingLog } from '@kbn/tooling-log'; | ||
|
||
import { getAllPlugins } from './lib'; | ||
|
||
interface Dependencies { | ||
required: readonly string[]; | ||
optional: readonly string[]; | ||
bundles?: readonly string[]; | ||
} | ||
|
||
const getSpaces = (size: number, count: number) => { | ||
const length = count > 9 && count < 100 ? 2 : count < 10 ? 1 : 3; | ||
return ' '.repeat(size - length); | ||
}; | ||
|
||
export const rankDependencies = (log: ToolingLog) => { | ||
const plugins = getAllPlugins(log); | ||
|
||
const pluginMap = new Map<string, Dependencies>(); | ||
const pluginRequired = new Map<string, number>(); | ||
const pluginOptional = new Map<string, number>(); | ||
const pluginBundles = new Map<string, number>(); | ||
let minWidth = 0; | ||
|
||
plugins.forEach((plugin) => { | ||
pluginMap.set(plugin.manifest.id, { | ||
required: plugin.manifest.requiredPlugins || [], | ||
optional: plugin.manifest.optionalPlugins || [], | ||
bundles: plugin.manifest.requiredBundles || [], | ||
}); | ||
|
||
if (plugin.manifest.id.length > minWidth) { | ||
minWidth = plugin.manifest.id.length; | ||
} | ||
}); | ||
|
||
pluginMap.forEach((dependencies) => { | ||
dependencies.required.forEach((required) => { | ||
pluginRequired.set(required, (pluginRequired.get(required) || 0) + 1); | ||
}); | ||
|
||
dependencies.optional.forEach((optional) => { | ||
pluginOptional.set(optional, (pluginOptional.get(optional) || 0) + 1); | ||
}); | ||
|
||
dependencies.bundles?.forEach((bundle) => { | ||
pluginBundles.set(bundle, (pluginBundles.get(bundle) || 0) + 1); | ||
}); | ||
}); | ||
|
||
const sorted = [...pluginMap.entries()].sort((a, b) => { | ||
const aRequired = pluginRequired.get(a[0]) || 0; | ||
const aOptional = pluginOptional.get(a[0]) || 0; | ||
const aBundles = pluginBundles.get(a[0]) || 0; | ||
const aTotal = aRequired + aOptional + aBundles; | ||
|
||
const bRequired = pluginRequired.get(b[0]) || 0; | ||
const bOptional = pluginOptional.get(b[0]) || 0; | ||
const bBundles = pluginBundles.get(b[0]) || 0; | ||
const bTotal = bRequired + bOptional + bBundles; | ||
|
||
return bTotal - aTotal; | ||
}); | ||
|
||
log.debug(`Ranking ${sorted.length} plugins.`); | ||
|
||
// sorted.forEach((plugin) => { | ||
// log.info(`${plugin[0]}: ${plugin[1]}/${pluginOptional.get(plugin[0]) || 0}`); | ||
// }); | ||
|
||
const multiBar = new MultiBar( | ||
{ | ||
clearOnComplete: false, | ||
hideCursor: true, | ||
format: ' {bar} | {plugin} | {usage} | {info}', | ||
}, | ||
Presets.shades_grey | ||
); | ||
|
||
multiBar.create(sorted.length, sorted.length, { | ||
plugin: `${sorted.length} plugins${' '.repeat(minWidth - 11)}`, | ||
usage: 'total', | ||
info: 'req opt bun', | ||
}); | ||
|
||
sorted.forEach(([plugin]) => { | ||
const total = sorted.length; | ||
const optional = pluginOptional.get(plugin) || 0; | ||
const required = pluginRequired.get(plugin) || 0; | ||
const bundles = pluginBundles.get(plugin) || 0; | ||
const usage = optional + required + bundles; | ||
|
||
multiBar.create(total, required + optional + bundles, { | ||
plugin: `${plugin}${' '.repeat(minWidth - plugin.length)}`, | ||
info: `${required}${getSpaces(4, required)}${optional}${getSpaces( | ||
4, | ||
optional | ||
)}${bundles}${getSpaces(4, bundles)}`, | ||
usage: `${usage}${getSpaces(5, usage)}`, | ||
}); | ||
}); | ||
|
||
multiBar.stop(); | ||
|
||
return sorted; | ||
}; |