Add components to available plugins
Co-authored-by: Vincenzo Scamporlino <vinzscam@users.noreply.github.com> Signed-off-by: Philipp Hugenroth <philipph@spotify.com>
This commit is contained in:
committed by
Patrik Oldsberg
parent
12c3fadb6d
commit
1d527ae2b6
@@ -27,5 +27,8 @@
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
]
|
||||
],
|
||||
"dependencies": {
|
||||
"@backstage/core-plugin-api": "workspace:^"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,16 +14,61 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
type Modules = Array<{
|
||||
name: string;
|
||||
module: object; // Loaded Webpack Module of Backstage Plugin
|
||||
}>;
|
||||
import { BackstagePlugin } from '@backstage/core-plugin-api';
|
||||
|
||||
function getAvailablePlugins() {
|
||||
const { modules }: { modules: Modules } = __webpack_require__(
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
type DetectedPlugin = {
|
||||
name: string;
|
||||
plugin: BackstagePlugin;
|
||||
components: Record<string, any>;
|
||||
};
|
||||
|
||||
type DetectedModule = {
|
||||
name: string;
|
||||
module: Record<string, any>;
|
||||
};
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
function getAvailablePlugins(): DetectedPlugin[] {
|
||||
const { modules } = __webpack_require__(
|
||||
'./node_modules/backstage-autodetected-plugins.js',
|
||||
) as { modules: DetectedModule[] };
|
||||
|
||||
return modules
|
||||
.map(splitPluginFromComponents)
|
||||
.filter((m): m is DetectedPlugin => !!m.plugin);
|
||||
}
|
||||
|
||||
function splitPluginFromComponents({ module, name }: DetectedModule) {
|
||||
return Object.entries(module).reduce(
|
||||
(acc, [k, v]) => {
|
||||
if (!isBackstagePlugin(v)) {
|
||||
acc.components[k] = v;
|
||||
} else {
|
||||
acc.plugin = v;
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
{ name, components: {} } as {
|
||||
name: string;
|
||||
plugin?: BackstagePlugin;
|
||||
components: Record<string, any>;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function isBackstagePlugin(obj: Record<string, any>): obj is BackstagePlugin {
|
||||
return (
|
||||
typeof obj.getId !== 'undefined' &&
|
||||
typeof obj.getApis !== 'undefined' &&
|
||||
typeof obj.getFeatureFlags !== 'undefined' &&
|
||||
typeof obj.provide !== 'undefined'
|
||||
);
|
||||
return modules;
|
||||
}
|
||||
|
||||
export { getAvailablePlugins };
|
||||
export type { DetectedPlugin };
|
||||
|
||||
@@ -78,16 +78,15 @@ export const InfoContent = () => {
|
||||
const classes = useStyles();
|
||||
const { about, loading, error } = useInfo();
|
||||
const plugins = autodetect.getAvailablePlugins();
|
||||
const availablePlugins: PackageDependency[] = (
|
||||
plugins as Array<Record<string, any>>
|
||||
).map(({ name, module }) => {
|
||||
const pluginImpl: any = Object.values(module).find((v: any) => !!v?.getId);
|
||||
|
||||
return {
|
||||
name,
|
||||
versions: (pluginImpl?.getId() as string) || '',
|
||||
};
|
||||
});
|
||||
const availablePlugins: PackageDependency[] = plugins.map(
|
||||
({ name, components }) => {
|
||||
return {
|
||||
name,
|
||||
versions: Object.keys(components).toString(),
|
||||
};
|
||||
},
|
||||
);
|
||||
if (loading) {
|
||||
return <Progress />;
|
||||
} else if (error) {
|
||||
|
||||
Reference in New Issue
Block a user