4.4. Creating a TechDocs add-on
If your organization has documentation needs that are not met by the functions of existing TechDocs add-ons, developers can create a new add-on for your TechDocs plugin.
A TechDocs add-on is a React component that is imported from a front-end plugin. If you do not have an existing plugin that you can use to export your TechDocs add-on, you can create a new plugin by using backstage-cli to generate a default front-end plugin structure that you can customize.
The folder structure of a new plugin that can be used to import TechDocs add-ons into the TechDocs plugin looks similar to the following example:
<new_plugin_for_techdocs_add-on>/
dev/
index.ts
src/
components/
<new_techdocs_add-on_component>/
<new_techdocs_add-on_component>.test.tsx
<new_techdocs_add-on_component>.tsx
index.ts
<new_techdocs_add-on_fetch-component>/
<new_techdocs_add-on_fetch-component>.test.tsx
<new_techdocs_add-on_fetch-component>.tsx
index.ts
index.ts
plugin.test.ts
plugin.ts
routes.ts
setupTests.ts
.eslintrc.js
package.json
README.md
Prerequisites
-
The
yarnpackage manager is installed. - Docker v3.2.0 or later or Podman v3.2.0 or later is installed and running.
Procedure
- In the terminal, navigate to the root folder of the repository where you want to create your new plugin.
To create a new front-end plugin, run the following command:
yarn newExample output
? What do you want to create? plugin - A new frontend plugin ? Enter the ID of the plugin [required]In the terminal prompt, type a name for the new plugin. For example:
? Enter the ID of the plugin [required] <new_plugin_for_techdocs_add-on>Example output
Successfully created pluginResult
In the
pluginsdirectory, a sub-directory with the same name that you gave to your plugin is automatically generated. The directory contains all of the files that you need to configure to create your new plugin.In the terminal, navigate to your new plugin directory. For example:
cd plugins/<new_techdocs_add-on_directory>Add the`@backstage/plugin-techdocs-react` package to get frontend utilities for TechDocs add-ons. For example:
yarn add @backstage/plugin-techdocs-react-
In the directory containing the components of your custom TechDocs add-on, delete any default files or file components that are not required for your add-on, such as the
routes.tsfile or components of theindex.tsxandplugins.tsfiles. In the
plugins.tsfile, add the following code:import { createPlugin } from '@backstage/core-plugin-api'; import { createTechDocsAddonExtension } from '@backstage/plugin-techdocs-react'; export const <new_plugin_for_techdocs_add-on> = createPlugin({ id: '<new_techdocs_add-on>', }); /* * * @public */ export const <new_techdocs_add-on> = <new_plugin_for_techdocs_add-on>.provide( createTechDocsAddonExtension<_<new_techdocs_addon_props>_>({ name: '<new_techdocs_add-on>', location: TechDocsAddonLocations.Content, component: <new_techdocs_add-on_component>, }), );where
- <new_plugin_for_techdocs_add-on>
- Specifies the new plugin that you use to import the TechDocs add-on to your Red Hat Developer Hub instance.
- <new_techdocs_add-on>
- Specifies the custom TechDocs add-on that you want to create.
- <new_techdocs_addon_props> (Optional)
-
Specifies the
propsfor your new TechDocs add-on, as specified in your<new_techdocs_add-on>.tsxfile, if applicable. - <new_techdocs_add-on_component>
-
Specifies the React component for the custom TechDocs add-on that you want to create. You will create this component in a
.tsxfile in a later step.
In the
index.tsfile, export the custom TechDocs add-on that you want to create by adding the following code:export { <new_plugin_for_techdocs_add-on>, <new_techdocs_add-on> } from './plugin';-
Create a new
<new_techdocs_add-on>.tsxfile and add the code for your new TechDocs add-on component. Create a new
index.tsxfile and use it to export your new TechDocs add-on component by adding the following code:export { <new_techdocs_add-on>, type <new_techdocs_addon_props>} from './<new_techdocs_add-on_directory>'where
- <new_techdocs_addon_props> (Optional)
-
Specifies the
propsfor your new TechDocs add-on, as specified in your<new_techdocs_add-on>.tsxfile, if applicable.
-
In the
plugins.tsfile, import your new TechDocs add-on component. - Install and configure your new TechDocs add-on by following the steps in Installing and configuring a TechDocs add-on
Verification
- Restart the RHDH application and verify that the plugin is successfully activated and configured.
- Verify the application logs for confirmation and ensure the plugin is functioning as expected.