From 718b7344331c4e5d37915a0f3aabe5c7976c90fe Mon Sep 17 00:00:00 2001 From: secustor Date: Tue, 27 Feb 2024 11:42:31 +0100 Subject: [PATCH 1/5] feat(plugins/techdocs): add TechdocsGeneratorExtensionPoint Signed-off-by: secustor --- .changeset/gorgeous-rats-leave.md | 6 ++++++ plugins/techdocs-backend/src/plugin.ts | 14 +++++++++++++ plugins/techdocs-node/src/extensions.ts | 20 +++++++++++++++++++ plugins/techdocs-node/src/index.ts | 1 + .../src/stages/generate/generators.ts | 9 +++++++-- 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 .changeset/gorgeous-rats-leave.md 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; From 8531bfdbb0399a7b19827607aca1cd454cd81968 Mon Sep 17 00:00:00 2001 From: secustor Date: Tue, 27 Feb 2024 11:44:24 +0100 Subject: [PATCH 2/5] feat(plugins/techdocs): add TechdocsGeneratorExtensionPoint Signed-off-by: secustor --- .changeset/gorgeous-rats-leave.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/gorgeous-rats-leave.md b/.changeset/gorgeous-rats-leave.md index 48264c1c7c..8729804d2b 100644 --- a/.changeset/gorgeous-rats-leave.md +++ b/.changeset/gorgeous-rats-leave.md @@ -3,4 +3,4 @@ '@backstage/plugin-techdocs-node': minor --- -Create extension point `TechdocsGeneratorExtensionPoint` to allow adding a custom custom generator +Create extension point `TechdocsGeneratorExtensionPoint` to allow adding a custom generator From 22e11bb48c9e9060ae95862f3dadd6f938248a40 Mon Sep 17 00:00:00 2001 From: secustor Date: Tue, 27 Feb 2024 21:55:32 +0100 Subject: [PATCH 3/5] chore: fix variable name Signed-off-by: secustor --- plugins/techdocs-backend/src/plugin.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/techdocs-backend/src/plugin.ts b/plugins/techdocs-backend/src/plugin.ts index 0ae4c470bc..78e0b07e5c 100644 --- a/plugins/techdocs-backend/src/plugin.ts +++ b/plugins/techdocs-backend/src/plugin.ts @@ -53,14 +53,14 @@ export const techdocsPlugin = createBackendPlugin({ }, }); - let customTechdosGenerator: TechdocsGenerator | undefined; + let customTechdocsGenerator: TechdocsGenerator | undefined; env.registerExtensionPoint(techdocsGeneratorExtensionPoint, { setTechdocsGenerator(generator: TechdocsGenerator) { - if (customTechdosGenerator) { + if (customTechdocsGenerator) { throw new Error('TechdocsGenerator may only be set once'); } - customTechdosGenerator = generator; + customTechdocsGenerator = generator; }, }); @@ -89,7 +89,7 @@ export const techdocsPlugin = createBackendPlugin({ const generators = await Generators.fromConfig(config, { logger: winstonLogger, containerRunner, - customGenerator: customTechdosGenerator, + customGenerator: customTechdocsGenerator, }); // Publisher is used for From 9f92b0adc1c4503e79bbd633ba85ec8cc4908ac7 Mon Sep 17 00:00:00 2001 From: secustor Date: Tue, 27 Feb 2024 22:44:55 +0100 Subject: [PATCH 4/5] chore: fix api report Signed-off-by: secustor --- plugins/techdocs-node/api-report.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/techdocs-node/api-report.md b/plugins/techdocs-node/api-report.md index 5203d30faa..1010eeef73 100644 --- a/plugins/techdocs-node/api-report.md +++ b/plugins/techdocs-node/api-report.md @@ -72,6 +72,7 @@ export class Generators implements GeneratorBuilder { options: { logger: Logger; containerRunner: ContainerRunner; + customGenerator?: TechdocsGenerator; }, ): Promise; get(entity: Entity): GeneratorBase; @@ -272,6 +273,11 @@ export class TechdocsGenerator implements GeneratorBase { run(options: GeneratorRunOptions): Promise; } +// Warning: (ae-forgotten-export) The symbol "TechdocsGeneratorExtensionPoint" needs to be exported by the entry point index.d.ts +// +// @public +export const techdocsGeneratorExtensionPoint: ExtensionPoint; + // @public export type TechDocsMetadata = { site_name: string; From 27a4c72396144009d9d7aba110389a67fea3ffa7 Mon Sep 17 00:00:00 2001 From: secustor Date: Tue, 27 Feb 2024 22:54:50 +0100 Subject: [PATCH 5/5] chore: fix api report Signed-off-by: secustor --- plugins/techdocs-node/api-report.md | 8 ++++++-- plugins/techdocs-node/src/index.ts | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/techdocs-node/api-report.md b/plugins/techdocs-node/api-report.md index 1010eeef73..caa46fb87c 100644 --- a/plugins/techdocs-node/api-report.md +++ b/plugins/techdocs-node/api-report.md @@ -273,8 +273,12 @@ export class TechdocsGenerator implements GeneratorBase { run(options: GeneratorRunOptions): Promise; } -// Warning: (ae-forgotten-export) The symbol "TechdocsGeneratorExtensionPoint" needs to be exported by the entry point index.d.ts -// +// @public +export interface TechdocsGeneratorExtensionPoint { + // (undocumented) + setTechdocsGenerator(generator: TechdocsGenerator): void; +} + // @public export const techdocsGeneratorExtensionPoint: ExtensionPoint; diff --git a/plugins/techdocs-node/src/index.ts b/plugins/techdocs-node/src/index.ts index 82165f9302..5dd81c3233 100644 --- a/plugins/techdocs-node/src/index.ts +++ b/plugins/techdocs-node/src/index.ts @@ -27,4 +27,5 @@ export { techdocsBuildsExtensionPoint, techdocsGeneratorExtensionPoint, type TechdocsBuildsExtensionPoint, + type TechdocsGeneratorExtensionPoint, } from './extensions';