From 92b495328bd3a3627c2b91b107c3175b10d44ab2 Mon Sep 17 00:00:00 2001 From: Oleg S <97077423+RobotSail@users.noreply.github.com> Date: Mon, 6 Mar 2023 17:00:01 -0500 Subject: [PATCH 1/4] expose the techdocs-backend plugin using the new system Signed-off-by: Oleg S <97077423+RobotSail@users.noreply.github.com> --- .changeset/large-feet-wash.md | 6 ++ packages/backend-next/package.json | 1 + packages/backend-next/src/index.ts | 2 + plugins/techdocs-backend/api-report.md | 4 ++ plugins/techdocs-backend/package.json | 1 + plugins/techdocs-backend/src/index.ts | 1 + plugins/techdocs-backend/src/plugin.ts | 95 ++++++++++++++++++++++++++ yarn.lock | 2 + 8 files changed, 112 insertions(+) create mode 100644 .changeset/large-feet-wash.md create mode 100644 plugins/techdocs-backend/src/plugin.ts diff --git a/.changeset/large-feet-wash.md b/.changeset/large-feet-wash.md new file mode 100644 index 0000000000..15e3c54b42 --- /dev/null +++ b/.changeset/large-feet-wash.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-techdocs-backend': minor +'example-backend-next': minor +--- + +Expose the techdocs-backend plugin using the new plugin system diff --git a/packages/backend-next/package.json b/packages/backend-next/package.json index 9f7ec8306a..5d8a8cb1ec 100644 --- a/packages/backend-next/package.json +++ b/packages/backend-next/package.json @@ -29,6 +29,7 @@ "@backstage/plugin-app-backend": "workspace:^", "@backstage/plugin-catalog-backend": "workspace:^", "@backstage/plugin-scaffolder-backend": "workspace:^", + "@backstage/plugin-techdocs-backend": "workspace:^", "@backstage/plugin-todo-backend": "workspace:^" }, "devDependencies": { diff --git a/packages/backend-next/src/index.ts b/packages/backend-next/src/index.ts index 8e29244ebf..0f7af110e9 100644 --- a/packages/backend-next/src/index.ts +++ b/packages/backend-next/src/index.ts @@ -19,6 +19,7 @@ import { catalogModuleTemplateKind } from '@backstage/plugin-scaffolder-backend/ import { createBackend } from '@backstage/backend-defaults'; import { appPlugin } from '@backstage/plugin-app-backend/alpha'; import { todoPlugin } from '@backstage/plugin-todo-backend'; +import { techdocsPlugin } from '@backstage/plugin-techdocs-backend'; const backend = createBackend(); @@ -26,4 +27,5 @@ backend.add(catalogPlugin()); backend.add(catalogModuleTemplateKind()); backend.add(appPlugin({ appPackageName: 'example-app' })); backend.add(todoPlugin()); +backend.add(techdocsPlugin()); backend.start(); diff --git a/plugins/techdocs-backend/api-report.md b/plugins/techdocs-backend/api-report.md index 1f6aa1d66a..fe8db9a135 100644 --- a/plugins/techdocs-backend/api-report.md +++ b/plugins/techdocs-backend/api-report.md @@ -5,6 +5,7 @@ ```ts /// +import { BackendFeature } from '@backstage/backend-plugin-api'; import { CatalogApi } from '@backstage/catalog-client'; import { CatalogClient } from '@backstage/catalog-client'; import { Config } from '@backstage/config'; @@ -129,5 +130,8 @@ export type TechDocsCollatorOptions = { export { TechDocsDocument }; +// @public +export const techdocsPlugin: () => BackendFeature; + export * from '@backstage/plugin-techdocs-node'; ``` diff --git a/plugins/techdocs-backend/package.json b/plugins/techdocs-backend/package.json index c9fff25b70..6389487eec 100644 --- a/plugins/techdocs-backend/package.json +++ b/plugins/techdocs-backend/package.json @@ -34,6 +34,7 @@ }, "dependencies": { "@backstage/backend-common": "workspace:^", + "@backstage/backend-plugin-api": "workspace:^", "@backstage/catalog-client": "workspace:^", "@backstage/catalog-model": "workspace:^", "@backstage/config": "workspace:^", diff --git a/plugins/techdocs-backend/src/index.ts b/plugins/techdocs-backend/src/index.ts index dc5d87d1b3..06259d3d3c 100644 --- a/plugins/techdocs-backend/src/index.ts +++ b/plugins/techdocs-backend/src/index.ts @@ -37,6 +37,7 @@ export type { TechDocsCollatorFactoryOptions, TechDocsCollatorOptions, } from './search'; +export { techdocsPlugin } from './plugin'; /** * @deprecated Use directly from @backstage/plugin-techdocs-node diff --git a/plugins/techdocs-backend/src/plugin.ts b/plugins/techdocs-backend/src/plugin.ts new file mode 100644 index 0000000000..7cffcc8fbd --- /dev/null +++ b/plugins/techdocs-backend/src/plugin.ts @@ -0,0 +1,95 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + DockerContainerRunner, + loggerToWinstonLogger, + cacheToPluginCacheManager, +} from '@backstage/backend-common'; +import { + coreServices, + createBackendPlugin, +} from '@backstage/backend-plugin-api'; + +import { + Preparers, + Generators, + Publisher, +} from '@backstage/plugin-techdocs-node'; +import Docker from 'dockerode'; +import { createRouter } from './service'; + +/** + * The TechDocs plugin is responsible for serving and building documentation for any entity. + * @public + */ +export const techdocsPlugin = createBackendPlugin({ + pluginId: 'techdocs-backend', + register(env) { + env.registerInit({ + deps: { + config: coreServices.config, + logger: coreServices.logger, + urlReader: coreServices.urlReader, + http: coreServices.httpRouter, + discovery: coreServices.discovery, + cache: coreServices.cache, + }, + async init({ config, logger, urlReader, http, discovery, cache }) { + const winstonLogger = loggerToWinstonLogger(logger); + // Preparers are responsible for fetching source files for documentation. + const preparers = await Preparers.fromConfig(config, { + reader: urlReader, + logger: winstonLogger, + }); + + // Docker client (conditionally) used by the generators, based on techdocs.generators config. + const dockerClient = new Docker(); + const containerRunner = new DockerContainerRunner({ dockerClient }); + + // Generators are used for generating documentation sites. + const generators = await Generators.fromConfig(config, { + logger: winstonLogger, + containerRunner, + }); + + // Publisher is used for + // 1. Publishing generated files to storage + // 2. Fetching files from storage and passing them to TechDocs frontend. + const publisher = await Publisher.fromConfig(config, { + logger: winstonLogger, + discovery: discovery, + }); + + // checks if the publisher is working and logs the result + await publisher.getReadiness(); + + const cacheManager = cacheToPluginCacheManager(cache); + http.use( + await createRouter({ + logger: winstonLogger, + cache: cacheManager, + preparers, + generators, + publisher, + config, + discovery, + }), + ); + }, + }); + }, +}); diff --git a/yarn.lock b/yarn.lock index 663107e961..6a8317bfce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8538,6 +8538,7 @@ __metadata: resolution: "@backstage/plugin-techdocs-backend@workspace:plugins/techdocs-backend" dependencies: "@backstage/backend-common": "workspace:^" + "@backstage/backend-plugin-api": "workspace:^" "@backstage/backend-test-utils": "workspace:^" "@backstage/catalog-client": "workspace:^" "@backstage/catalog-model": "workspace:^" @@ -22870,6 +22871,7 @@ __metadata: "@backstage/plugin-app-backend": "workspace:^" "@backstage/plugin-catalog-backend": "workspace:^" "@backstage/plugin-scaffolder-backend": "workspace:^" + "@backstage/plugin-techdocs-backend": "workspace:^" "@backstage/plugin-todo-backend": "workspace:^" languageName: unknown linkType: soft From c041efd53d64b72db7e217acb70f9d367b54bd35 Mon Sep 17 00:00:00 2001 From: Oleg S <97077423+RobotSail@users.noreply.github.com> Date: Wed, 8 Mar 2023 15:30:37 -0500 Subject: [PATCH 2/4] exposes the techdocs plugin as an alpha plugin Signed-off-by: Oleg S <97077423+RobotSail@users.noreply.github.com> --- .changeset/large-feet-wash.md | 3 +-- packages/backend-next/src/index.ts | 2 +- plugins/techdocs-backend/alpha-api-report.md | 12 ++++++++++++ plugins/techdocs-backend/api-report.md | 4 ---- plugins/techdocs-backend/package.json | 15 +++++++++++++++ plugins/techdocs-backend/src/alpha.ts | 16 ++++++++++++++++ plugins/techdocs-backend/src/index.ts | 1 - plugins/techdocs-backend/src/plugin.ts | 4 ++-- 8 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 plugins/techdocs-backend/alpha-api-report.md create mode 100644 plugins/techdocs-backend/src/alpha.ts diff --git a/.changeset/large-feet-wash.md b/.changeset/large-feet-wash.md index 15e3c54b42..d663661725 100644 --- a/.changeset/large-feet-wash.md +++ b/.changeset/large-feet-wash.md @@ -1,6 +1,5 @@ --- '@backstage/plugin-techdocs-backend': minor -'example-backend-next': minor --- -Expose the techdocs-backend plugin using the new plugin system +Added alpha export of the `techdocsPlugin` using the new backend system diff --git a/packages/backend-next/src/index.ts b/packages/backend-next/src/index.ts index 0f7af110e9..8f8984b192 100644 --- a/packages/backend-next/src/index.ts +++ b/packages/backend-next/src/index.ts @@ -19,7 +19,7 @@ import { catalogModuleTemplateKind } from '@backstage/plugin-scaffolder-backend/ import { createBackend } from '@backstage/backend-defaults'; import { appPlugin } from '@backstage/plugin-app-backend/alpha'; import { todoPlugin } from '@backstage/plugin-todo-backend'; -import { techdocsPlugin } from '@backstage/plugin-techdocs-backend'; +import { techdocsPlugin } from '@backstage/plugin-techdocs-backend/alpha'; const backend = createBackend(); diff --git a/plugins/techdocs-backend/alpha-api-report.md b/plugins/techdocs-backend/alpha-api-report.md new file mode 100644 index 0000000000..16db84c216 --- /dev/null +++ b/plugins/techdocs-backend/alpha-api-report.md @@ -0,0 +1,12 @@ +## API Report File for "@backstage/plugin-techdocs-backend" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +import { BackendFeature } from '@backstage/backend-plugin-api'; + +// @alpha +export const techdocsPlugin: () => BackendFeature; + +// (No @packageDocumentation comment for this package) +``` diff --git a/plugins/techdocs-backend/api-report.md b/plugins/techdocs-backend/api-report.md index fe8db9a135..1f6aa1d66a 100644 --- a/plugins/techdocs-backend/api-report.md +++ b/plugins/techdocs-backend/api-report.md @@ -5,7 +5,6 @@ ```ts /// -import { BackendFeature } from '@backstage/backend-plugin-api'; import { CatalogApi } from '@backstage/catalog-client'; import { CatalogClient } from '@backstage/catalog-client'; import { Config } from '@backstage/config'; @@ -130,8 +129,5 @@ export type TechDocsCollatorOptions = { export { TechDocsDocument }; -// @public -export const techdocsPlugin: () => BackendFeature; - export * from '@backstage/plugin-techdocs-node'; ``` diff --git a/plugins/techdocs-backend/package.json b/plugins/techdocs-backend/package.json index 6389487eec..1d2f4400eb 100644 --- a/plugins/techdocs-backend/package.json +++ b/plugins/techdocs-backend/package.json @@ -10,6 +10,21 @@ "main": "dist/index.cjs.js", "types": "dist/index.d.ts" }, + "exports": { + ".": "./src/index.ts", + "./alpha": "./src/alpha.ts", + "./package.json": "./package.json" + }, + "typesVersions": { + "*": { + "alpha": [ + "src/alpha.ts" + ], + "package.json": [ + "package.json" + ] + } + }, "backstage": { "role": "backend-plugin" }, diff --git a/plugins/techdocs-backend/src/alpha.ts b/plugins/techdocs-backend/src/alpha.ts new file mode 100644 index 0000000000..1a36c5a1f5 --- /dev/null +++ b/plugins/techdocs-backend/src/alpha.ts @@ -0,0 +1,16 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export { techdocsPlugin } from './plugin'; diff --git a/plugins/techdocs-backend/src/index.ts b/plugins/techdocs-backend/src/index.ts index 06259d3d3c..dc5d87d1b3 100644 --- a/plugins/techdocs-backend/src/index.ts +++ b/plugins/techdocs-backend/src/index.ts @@ -37,7 +37,6 @@ export type { TechDocsCollatorFactoryOptions, TechDocsCollatorOptions, } from './search'; -export { techdocsPlugin } from './plugin'; /** * @deprecated Use directly from @backstage/plugin-techdocs-node diff --git a/plugins/techdocs-backend/src/plugin.ts b/plugins/techdocs-backend/src/plugin.ts index 7cffcc8fbd..4b0ebbe366 100644 --- a/plugins/techdocs-backend/src/plugin.ts +++ b/plugins/techdocs-backend/src/plugin.ts @@ -30,11 +30,11 @@ import { Publisher, } from '@backstage/plugin-techdocs-node'; import Docker from 'dockerode'; -import { createRouter } from './service'; +import { createRouter } from '@backstage/plugin-techdocs-backend'; /** * The TechDocs plugin is responsible for serving and building documentation for any entity. - * @public + * @alpha */ export const techdocsPlugin = createBackendPlugin({ pluginId: 'techdocs-backend', From a09223a505fd36574d0b57beb340896eddb12702 Mon Sep 17 00:00:00 2001 From: Oleg S <97077423+RobotSail@users.noreply.github.com> Date: Thu, 9 Mar 2023 09:52:33 -0500 Subject: [PATCH 3/4] rename pluginId for todo-backend & techdocs-backend to 'todo' and 'techdocs' Signed-off-by: Oleg S <97077423+RobotSail@users.noreply.github.com> --- .changeset/large-feet-wash.md | 3 ++- plugins/techdocs-backend/src/plugin.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.changeset/large-feet-wash.md b/.changeset/large-feet-wash.md index d663661725..2a55aab2c9 100644 --- a/.changeset/large-feet-wash.md +++ b/.changeset/large-feet-wash.md @@ -1,5 +1,6 @@ --- '@backstage/plugin-techdocs-backend': minor +'@backstage/plugin-todo-backend': patch --- -Added alpha export of the `techdocsPlugin` using the new backend system +Added alpha export of the `techdocsPlugin` using the new backend system. Renamed the `todoPlugin` pluginId from `todo-backend` to `todo`. diff --git a/plugins/techdocs-backend/src/plugin.ts b/plugins/techdocs-backend/src/plugin.ts index 4b0ebbe366..134de2bba6 100644 --- a/plugins/techdocs-backend/src/plugin.ts +++ b/plugins/techdocs-backend/src/plugin.ts @@ -37,7 +37,7 @@ import { createRouter } from '@backstage/plugin-techdocs-backend'; * @alpha */ export const techdocsPlugin = createBackendPlugin({ - pluginId: 'techdocs-backend', + pluginId: 'techdocs', register(env) { env.registerInit({ deps: { From 2f2f5112adad5bd11d923d3aabf850afd00a5e3b Mon Sep 17 00:00:00 2001 From: Oleg S <97077423+RobotSail@users.noreply.github.com> Date: Thu, 9 Mar 2023 11:23:18 -0500 Subject: [PATCH 4/4] spelling Signed-off-by: Oleg S <97077423+RobotSail@users.noreply.github.com> --- .changeset/large-feet-wash.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.changeset/large-feet-wash.md b/.changeset/large-feet-wash.md index 2a55aab2c9..88a28f9d60 100644 --- a/.changeset/large-feet-wash.md +++ b/.changeset/large-feet-wash.md @@ -1,6 +1,5 @@ --- '@backstage/plugin-techdocs-backend': minor -'@backstage/plugin-todo-backend': patch --- -Added alpha export of the `techdocsPlugin` using the new backend system. Renamed the `todoPlugin` pluginId from `todo-backend` to `todo`. +Introduced alpha export of the `techdocsPlugin` using the new backend system.