message: Allow either out-of-the-box or recommended configurations in TechDocs createRouter
diff: @@ -31,7 +31,11 @@ import { Logger } from 'winston';
  import { DocsBuilder } from '../DocsBuilder';
  import { shouldCheckForUpdate } from '../DocsBuilder/BuildMetadataStorage';
  -type RouterOptions = {
  +/**
  + * All of the required dependencies for running TechDocs in the "out-of-the-box"
  + * deployment configuration (prepare/generate/publish all in the Backend).
  + */
  +type OutOfTheBoxDeploymentOptions = {
  preparers: PreparerBuilder;
  generators: GeneratorBuilder;
  publisher: PublisherBase;
  @@ -41,15 +45,39 @@ type RouterOptions = {
  config: Config;
  };
  -export async function createRouter({
  - preparers,
  - generators,
  - publisher,
  - config,
  - logger,
  - discovery,
  -}: RouterOptions): Promise<express.Router> {
  +/**
  + * Required dependencies for running TechDocs in the "recommended" deployment
  + * configuration (prepare/generate handled externally in CI/CD).
  + */
  +type RecommendedDeploymentOptions = {
  + publisher: PublisherBase;
  + logger: Logger;
  + discovery: PluginEndpointDiscovery;
  + config: Config;
  +};
  +
  +/**
  + * One of the two deployment configurations must be provided.
  + */
  +type RouterOptions =
  + | RecommendedDeploymentOptions
  + | OutOfTheBoxDeploymentOptions;
  +
  +/**
  + * Typeguard to help createRouter() understand when we are in a "recommended"
  + * deployment vs. when we are in an out-of-the-box deployment configuration.
  + */
  +function isOutOfTheBoxOption(
  + opt: RouterOptions,
  +): opt is OutOfTheBoxDeploymentOptions {
  + return (opt as OutOfTheBoxDeploymentOptions).preparers !== undefined;
  +}
  +
  +export async function createRouter(
  + options: RouterOptions,
  +): Promise<express.Router> {
  const router = Router();
  + const { publisher, config, logger, discovery } = options;
  router.get('/metadata/techdocs/:namespace/:kind/:name', async (req, res) => {
  const { kind, namespace, name } = req.params;
  @@ -158,6 +186,10 @@ export async function createRouter({
  });
  return;
  }
  +
  + // Set up a DocsBuilder if "out-of-the-box" configuration is provided.
  + if (isOutOfTheBoxOption(options)) {
  + const { preparers, generators } = options;
  const docsBuilder = new DocsBuilder({
  preparers,
  generators,
  @@ -211,6 +243,7 @@ export async function createRouter({
  `Publisher type ${publisherType} is not supported by techdocs-backend docs builder.`,
  );
  }
  + }
  });
  // Route middleware which serves files from the storage set in the publisher.
  