feat: allow overriding default techdocs preparers
a new extension point `TechdocsPreparerExtensionPoint` allows registering custom preparers for the techdocs plugin. closes #21952 Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
cacheToPluginCacheManager,
|
||||
DockerContainerRunner,
|
||||
loggerToWinstonLogger,
|
||||
cacheToPluginCacheManager,
|
||||
} from '@backstage/backend-common';
|
||||
import {
|
||||
coreServices,
|
||||
@@ -26,12 +26,15 @@ import {
|
||||
|
||||
import {
|
||||
DocsBuildStrategy,
|
||||
Preparers,
|
||||
Generators,
|
||||
PreparerBase,
|
||||
Preparers,
|
||||
Publisher,
|
||||
RemoteProtocol,
|
||||
techdocsBuildsExtensionPoint,
|
||||
techdocsGeneratorExtensionPoint,
|
||||
TechdocsGenerator,
|
||||
techdocsGeneratorExtensionPoint,
|
||||
techdocsPreparerExtensionPoint,
|
||||
} from '@backstage/plugin-techdocs-node';
|
||||
import Docker from 'dockerode';
|
||||
import { createRouter } from '@backstage/plugin-techdocs-backend';
|
||||
@@ -64,6 +67,18 @@ export const techdocsPlugin = createBackendPlugin({
|
||||
},
|
||||
});
|
||||
|
||||
const customPreparers = new Map<RemoteProtocol, PreparerBase>();
|
||||
env.registerExtensionPoint(techdocsPreparerExtensionPoint, {
|
||||
registerPreparer(protocol: RemoteProtocol, preparer: PreparerBase) {
|
||||
if (customPreparers.has(protocol)) {
|
||||
throw new Error(
|
||||
`Preparer for protocol ${protocol} is already registered`,
|
||||
);
|
||||
}
|
||||
customPreparers.set(protocol, preparer);
|
||||
},
|
||||
});
|
||||
|
||||
env.registerInit({
|
||||
deps: {
|
||||
config: coreServices.rootConfig,
|
||||
@@ -91,6 +106,9 @@ export const techdocsPlugin = createBackendPlugin({
|
||||
reader: urlReader,
|
||||
logger: winstonLogger,
|
||||
});
|
||||
for (const [protocol, preparer] of customPreparers.entries()) {
|
||||
preparers.register(protocol, preparer);
|
||||
}
|
||||
|
||||
// Docker client (conditionally) used by the generators, based on techdocs.generators config.
|
||||
const dockerClient = new Docker();
|
||||
|
||||
Reference in New Issue
Block a user