From 248d1242bd27421621fcaed8cf54c28088bcd9c0 Mon Sep 17 00:00:00 2001 From: Andre Wanlin <67169551+awanlin@users.noreply.github.com> Date: Tue, 17 Jan 2023 12:44:05 -0600 Subject: [PATCH] Added property to track if config exists already Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com> --- .../generate/__fixtures__/mkdocs_default.yml | 2 +- .../src/stages/generate/helpers.test.ts | 37 +++++++++++++------ .../src/stages/generate/helpers.ts | 5 ++- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/plugins/techdocs-node/src/stages/generate/__fixtures__/mkdocs_default.yml b/plugins/techdocs-node/src/stages/generate/__fixtures__/mkdocs_default.yml index c0c5a203df..460e5c0e1d 100644 --- a/plugins/techdocs-node/src/stages/generate/__fixtures__/mkdocs_default.yml +++ b/plugins/techdocs-node/src/stages/generate/__fixtures__/mkdocs_default.yml @@ -1,4 +1,4 @@ -site_name: Test site name +site_name: Default Test site name docs_dir: docs plugins: - techdocs-core diff --git a/plugins/techdocs-node/src/stages/generate/helpers.test.ts b/plugins/techdocs-node/src/stages/generate/helpers.test.ts index a7fa11f3fd..186a685a90 100644 --- a/plugins/techdocs-node/src/stages/generate/helpers.test.ts +++ b/plugins/techdocs-node/src/stages/generate/helpers.test.ts @@ -190,6 +190,7 @@ describe('helpers', () => { beforeEach(() => { mockFs({ '/mkdocs.yml': mkdocsYml, + '/mkdocs_default.yml': mkdocsDefaultYml, '/mkdocs_with_repo_url.yml': mkdocsYmlWithRepoUrl, '/mkdocs_with_edit_uri.yml': mkdocsYmlWithEditUri, '/mkdocs_with_extensions.yml': mkdocsYmlWithExtensions, @@ -525,35 +526,47 @@ describe('helpers', () => { it('returns expected contents when .yml file is present', async () => { const key = path.join(inputDir, 'mkdocs.yml'); mockFs({ [key]: mkdocsYml }); - const { path: mkdocsPath, content } = await getMkdocsYml( - inputDir, - siteOptions, - ); + const { + path: mkdocsPath, + content, + configExists, + } = await getMkdocsYml(inputDir, siteOptions); expect(mkdocsPath).toBe(key); expect(content).toBe(mkdocsYml.toString()); + expect(configExists).toBe(true); }); it('returns expected contents when .yaml file is present', async () => { const key = path.join(inputDir, 'mkdocs.yaml'); mockFs({ [key]: mkdocsYml }); - const { path: mkdocsPath, content } = await getMkdocsYml( - inputDir, - siteOptions, - ); + const { + path: mkdocsPath, + content, + configExists, + } = await getMkdocsYml(inputDir, siteOptions); expect(mkdocsPath).toBe(key); expect(content).toBe(mkdocsYml.toString()); + expect(configExists).toBe(true); }); it('returns expected contents when default file is present', async () => { + const defaultSiteOptions = { + name: 'Default Test site name', + }; const key = path.join(inputDir, 'mkdocs.yml'); + const mockPathExists = jest.spyOn(fs, 'pathExists'); + mockPathExists.mockImplementation(() => Promise.resolve(false)); mockFs({ [key]: mkdocsDefaultYml }); - const { path: mkdocsPath, content } = await getMkdocsYml( - inputDir, - siteOptions, - ); + const { + path: mkdocsPath, + content, + configExists, + } = await getMkdocsYml(inputDir, defaultSiteOptions); + expect(mkdocsPath).toBe(key); expect(content).toBe(mkdocsDefaultYml.toString()); + expect(configExists).toBe(false); }); it('throws when neither .yml nor .yaml nor default file is present', async () => { diff --git a/plugins/techdocs-node/src/stages/generate/helpers.ts b/plugins/techdocs-node/src/stages/generate/helpers.ts index 5fc74eafc2..2f53e125f8 100644 --- a/plugins/techdocs-node/src/stages/generate/helpers.ts +++ b/plugins/techdocs-node/src/stages/generate/helpers.ts @@ -193,7 +193,7 @@ export const generateMkdocsYml = async ( export const getMkdocsYml = async ( inputDir: string, siteOptions?: { name?: string }, -): Promise<{ path: string; content: string }> => { +): Promise<{ path: string; content: string; configExists: boolean }> => { let mkdocsYmlPath: string; let mkdocsYmlFileString: string; try { @@ -203,6 +203,7 @@ export const getMkdocsYml = async ( return { path: mkdocsYmlPath, content: mkdocsYmlFileString, + configExists: true, }; } @@ -212,6 +213,7 @@ export const getMkdocsYml = async ( return { path: mkdocsYmlPath, content: mkdocsYmlFileString, + configExists: true, }; } @@ -228,6 +230,7 @@ export const getMkdocsYml = async ( return { path: mkdocsYmlPath, content: mkdocsYmlFileString, + configExists: false, }; };