diff --git a/.changeset/gorgeous-rats-leave.md b/.changeset/gorgeous-rats-leave.md new file mode 100644 index 0000000000..48264c1c7c --- /dev/null +++ b/.changeset/gorgeous-rats-leave.md @@ -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 diff --git a/plugins/techdocs-backend/src/plugin.ts b/plugins/techdocs-backend/src/plugin.ts index f139cf3c3a..0ae4c470bc 100644 --- a/plugins/techdocs-backend/src/plugin.ts +++ b/plugins/techdocs-backend/src/plugin.ts @@ -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 diff --git a/plugins/techdocs-node/src/extensions.ts b/plugins/techdocs-node/src/extensions.ts index c3a048b4e2..aec9153653 100644 --- a/plugins/techdocs-node/src/extensions.ts +++ b/plugins/techdocs-node/src/extensions.ts @@ -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({ 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({ + id: 'techdocs.generator', + }); diff --git a/plugins/techdocs-node/src/index.ts b/plugins/techdocs-node/src/index.ts index 640bd09ce0..82165f9302 100644 --- a/plugins/techdocs-node/src/index.ts +++ b/plugins/techdocs-node/src/index.ts @@ -25,5 +25,6 @@ export * from './helpers'; export * from './techdocsTypes'; export { techdocsBuildsExtensionPoint, + techdocsGeneratorExtensionPoint, type TechdocsBuildsExtensionPoint, } from './extensions'; diff --git a/plugins/techdocs-node/src/stages/generate/generators.ts b/plugins/techdocs-node/src/stages/generate/generators.ts index 630fccfa44..603c714370 100644 --- a/plugins/techdocs-node/src/stages/generate/generators.ts +++ b/plugins/techdocs-node/src/stages/generate/generators.ts @@ -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 { const generators = new Generators(); - const techdocsGenerator = TechdocsGenerator.fromConfig(config, options); + const techdocsGenerator = + options.customGenerator ?? TechdocsGenerator.fromConfig(config, options); generators.register('techdocs', techdocsGenerator); return generators;