feat(plugins/techdocs): add TechdocsGeneratorExtensionPoint
Signed-off-by: secustor <sebastian@poxhofer.at>
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@backstage/plugin-techdocs-backend': minor
|
||||
'@backstage/plugin-techdocs-node': minor
|
||||
---
|
||||
|
||||
Create extension point `TechdocsGeneratorExtensionPoint` to allow adding a custom custom generator
|
||||
@@ -30,6 +30,8 @@ import {
|
||||
Generators,
|
||||
Publisher,
|
||||
techdocsBuildsExtensionPoint,
|
||||
techdocsGeneratorExtensionPoint,
|
||||
TechdocsGenerator,
|
||||
} from '@backstage/plugin-techdocs-node';
|
||||
import Docker from 'dockerode';
|
||||
import { createRouter } from '@backstage/plugin-techdocs-backend';
|
||||
@@ -51,6 +53,17 @@ export const techdocsPlugin = createBackendPlugin({
|
||||
},
|
||||
});
|
||||
|
||||
let customTechdosGenerator: TechdocsGenerator | undefined;
|
||||
env.registerExtensionPoint(techdocsGeneratorExtensionPoint, {
|
||||
setTechdocsGenerator(generator: TechdocsGenerator) {
|
||||
if (customTechdosGenerator) {
|
||||
throw new Error('TechdocsGenerator may only be set once');
|
||||
}
|
||||
|
||||
customTechdosGenerator = generator;
|
||||
},
|
||||
});
|
||||
|
||||
env.registerInit({
|
||||
deps: {
|
||||
config: coreServices.rootConfig,
|
||||
@@ -76,6 +89,7 @@ export const techdocsPlugin = createBackendPlugin({
|
||||
const generators = await Generators.fromConfig(config, {
|
||||
logger: winstonLogger,
|
||||
containerRunner,
|
||||
customGenerator: customTechdosGenerator,
|
||||
});
|
||||
|
||||
// Publisher is used for
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
import { createExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
import { DocsBuildStrategy } from './techdocsTypes';
|
||||
import { TechdocsGenerator } from './stages';
|
||||
|
||||
/**
|
||||
* Extension point type for configuring Techdocs builds.
|
||||
@@ -34,3 +35,22 @@ export const techdocsBuildsExtensionPoint =
|
||||
createExtensionPoint<TechdocsBuildsExtensionPoint>({
|
||||
id: 'techdocs.builds',
|
||||
});
|
||||
|
||||
/**
|
||||
* Extension point type for configuring a custom Techdocs generator
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface TechdocsGeneratorExtensionPoint {
|
||||
setTechdocsGenerator(generator: TechdocsGenerator): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension point for configuring a custom Techdocs generator
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const techdocsGeneratorExtensionPoint =
|
||||
createExtensionPoint<TechdocsGeneratorExtensionPoint>({
|
||||
id: 'techdocs.generator',
|
||||
});
|
||||
|
||||
@@ -25,5 +25,6 @@ export * from './helpers';
|
||||
export * from './techdocsTypes';
|
||||
export {
|
||||
techdocsBuildsExtensionPoint,
|
||||
techdocsGeneratorExtensionPoint,
|
||||
type TechdocsBuildsExtensionPoint,
|
||||
} from './extensions';
|
||||
|
||||
@@ -40,11 +40,16 @@ export class Generators implements GeneratorBuilder {
|
||||
*/
|
||||
static async fromConfig(
|
||||
config: Config,
|
||||
options: { logger: Logger; containerRunner: ContainerRunner },
|
||||
options: {
|
||||
logger: Logger;
|
||||
containerRunner: ContainerRunner;
|
||||
customGenerator?: TechdocsGenerator;
|
||||
},
|
||||
): Promise<GeneratorBuilder> {
|
||||
const generators = new Generators();
|
||||
|
||||
const techdocsGenerator = TechdocsGenerator.fromConfig(config, options);
|
||||
const techdocsGenerator =
|
||||
options.customGenerator ?? TechdocsGenerator.fromConfig(config, options);
|
||||
generators.register('techdocs', techdocsGenerator);
|
||||
|
||||
return generators;
|
||||
|
||||
Reference in New Issue
Block a user