From 8e11504ce346e9e93ca7d5c721523f9d51845b9a Mon Sep 17 00:00:00 2001 From: Andre Wanlin <67169551+awanlin@users.noreply.github.com> Date: Tue, 17 Jan 2023 13:20:45 -0600 Subject: [PATCH] Use object for YAML file Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com> --- .../src/stages/generate/helpers.ts | 17 ++++++++++------- .../techdocs-node/src/stages/generate/types.ts | 6 ++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/plugins/techdocs-node/src/stages/generate/helpers.ts b/plugins/techdocs-node/src/stages/generate/helpers.ts index 2f53e125f8..c0a82da510 100644 --- a/plugins/techdocs-node/src/stages/generate/helpers.ts +++ b/plugins/techdocs-node/src/stages/generate/helpers.ts @@ -26,7 +26,7 @@ import path, { resolve as resolvePath } from 'path'; import { PassThrough, Writable } from 'stream'; import { Logger } from 'winston'; import { ParsedLocationAnnotation } from '../../helpers'; -import { SupportedGeneratorKey } from './types'; +import { DefaultMkdocsContent, SupportedGeneratorKey } from './types'; import { getFileTreeRecursively } from '../publish/helpers'; // TODO: Implement proper support for more generators. @@ -169,13 +169,16 @@ export const generateMkdocsYml = async ( const mkdocsYmlPath = path.join(inputDir, 'mkdocs.yml'); const defaultSiteName = siteOptions?.name ?? 'Documentation Site'; - const defaultMkdocsContent = - `site_name: ${defaultSiteName}\n` + - 'docs_dir: docs\n' + - 'plugins:\n' + - ' - techdocs-core\n'; + const defaultMkdocsContent: DefaultMkdocsContent = { + site_name: defaultSiteName, + docs_dir: 'docs', + plugins: ['techdocs-core'], + }; - await fs.writeFile(mkdocsYmlPath, defaultMkdocsContent); + await fs.writeFile( + mkdocsYmlPath, + yaml.dump(defaultMkdocsContent, { schema: MKDOCS_SCHEMA }), + ); } catch (error) { throw new ForwardedError('Could not generate mkdocs.yml file', error); } diff --git a/plugins/techdocs-node/src/stages/generate/types.ts b/plugins/techdocs-node/src/stages/generate/types.ts index 1d0c6bb8f2..70c332344a 100644 --- a/plugins/techdocs-node/src/stages/generate/types.ts +++ b/plugins/techdocs-node/src/stages/generate/types.ts @@ -91,3 +91,9 @@ export type GeneratorBuilder = { register(protocol: SupportedGeneratorKey, generator: GeneratorBase): void; get(entity: Entity): GeneratorBase; }; + +export type DefaultMkdocsContent = { + site_name: string; + docs_dir: string; + plugins: String[]; +};