From 69b2f7bf3bb9f437c3c71b4d40f4d81149462eb4 Mon Sep 17 00:00:00 2001 From: hainenber Date: Mon, 20 Nov 2023 21:46:41 +0700 Subject: [PATCH] fix(techdocs-cli): limit supported mkdocs flags Signed-off-by: hainenber --- docs/features/techdocs/cli.md | 4 +++- packages/techdocs-cli/cli-report.md | 3 +++ packages/techdocs-cli/src/commands/index.ts | 15 +++++++++++++-- packages/techdocs-cli/src/commands/serve/serve.ts | 5 +++-- .../techdocs-cli/src/lib/mkdocsServer.test.ts | 5 ++++- packages/techdocs-cli/src/lib/mkdocsServer.ts | 12 +++++++++--- 6 files changed, 35 insertions(+), 9 deletions(-) diff --git a/docs/features/techdocs/cli.md b/docs/features/techdocs/cli.md index 6a2407372f..e7b3aff057 100644 --- a/docs/features/techdocs/cli.md +++ b/docs/features/techdocs/cli.md @@ -91,7 +91,9 @@ Options: --docker-option Extra options to pass to the docker run command, e.g. "--add-host=internal.host:192.168.11.12" (can be added multiple times). --no-docker Do not use Docker, use MkDocs executable in current user environment. - --mkdocs-configs Extra mkdocs server to pass to mkdocs running in containerized environment. + --mkdocs-parameter-clean Pass "--clean" parameter to mkdocs server running in containerized environment. + --mkdocs-parameter-dirty Pass "--dirty" parameter to mkdocs server running in containerized environment. + --mkdocs-parameter-strict Pass "--strict" parameter to mkdocs server running in containerized environment. --mkdocs-port Port for MkDocs server to use (default: "8000") --preview-app-bundle-path Preview documentation using a web app other than the included one. --preview-app-port Port where the preview will be served. diff --git a/packages/techdocs-cli/cli-report.md b/packages/techdocs-cli/cli-report.md index 890718b0d2..9c155473ef 100644 --- a/packages/techdocs-cli/cli-report.md +++ b/packages/techdocs-cli/cli-report.md @@ -107,6 +107,9 @@ Options: --preview-app-bundle-path --preview-app-port -c, --mkdocs-config-file-name + --mkdocs-parameter-clean + --mkdocs-parameter-dirty + --mkdocs-parameter-strict -h, --help ``` diff --git a/packages/techdocs-cli/src/commands/index.ts b/packages/techdocs-cli/src/commands/index.ts index 3052575366..2d5ff98e77 100644 --- a/packages/techdocs-cli/src/commands/index.ts +++ b/packages/techdocs-cli/src/commands/index.ts @@ -290,8 +290,19 @@ export function registerCommands(program: Command) { 'Mkdocs config file name', ) .option( - '--mkdocs-configs', - 'Additional parameters to pass to containerized mkdocs', + '--mkdocs-parameter-clean', + 'Pass "--clean" parameter to mkdocs server running in containerized environment', + false, + ) + .option( + '--mkdocs-parameter-dirty', + 'Pass "--dirty" parameter to mkdocs server running in containerized environment', + false, + ) + .option( + '--mkdocs-parameter-strict', + 'Pass "--strict" parameter to mkdocs server running in containerized environment', + false, ) .hook('preAction', command => { if ( diff --git a/packages/techdocs-cli/src/commands/serve/serve.ts b/packages/techdocs-cli/src/commands/serve/serve.ts index 04a8cff2f6..47cfbe8a22 100644 --- a/packages/techdocs-cli/src/commands/serve/serve.ts +++ b/packages/techdocs-cli/src/commands/serve/serve.ts @@ -67,7 +67,6 @@ export default async function serve(opts: OptionValues) { ? mkdocsDockerAddr : mkdocsLocalAddr; const mkdocsConfigFileName = opts.mkdocsConfigFileName; - const mkdocsConfigs = opts.mkdocsConfig.split(' '); const siteName = opts.siteName; const { path: mkdocsYmlPath, configIsTemporary } = await getMkdocsYml('./', { @@ -117,7 +116,9 @@ export default async function serve(opts: OptionValues) { stdoutLogFunc: mkdocsLogFunc, stderrLogFunc: mkdocsLogFunc, mkdocsConfigFileName: mkdocsYmlPath, - mkdocsConfigs: mkdocsConfigs, + mkdocsParameterClean: opts.mkdocsParameterClean, + mkdocsParameterDirty: opts.mkdocsParameterDirty, + mkdocsParameterStrict: opts.mkdocsParameterStrict, }); // Wait until mkdocs server has started so that Backstage starts with docs loaded diff --git a/packages/techdocs-cli/src/lib/mkdocsServer.test.ts b/packages/techdocs-cli/src/lib/mkdocsServer.test.ts index 73203a69e9..83f9c9f382 100644 --- a/packages/techdocs-cli/src/lib/mkdocsServer.test.ts +++ b/packages/techdocs-cli/src/lib/mkdocsServer.test.ts @@ -99,7 +99,10 @@ describe('runMkdocsServer', () => { }); it('should accept additinoal mkdocs CLI parameters', async () => { - await runMkdocsServer({ mkdocsConfigs: ['--clean', '--strict'] }); + await runMkdocsServer({ + mkdocsParameterClean: true, + mkdocsParameterStrict: true, + }); expect(run).toHaveBeenCalledWith( 'docker', expect.arrayContaining([ diff --git a/packages/techdocs-cli/src/lib/mkdocsServer.ts b/packages/techdocs-cli/src/lib/mkdocsServer.ts index ff412bd87f..dced19cb7a 100644 --- a/packages/techdocs-cli/src/lib/mkdocsServer.ts +++ b/packages/techdocs-cli/src/lib/mkdocsServer.ts @@ -26,7 +26,9 @@ export const runMkdocsServer = async (options: { stdoutLogFunc?: LogFunc; stderrLogFunc?: LogFunc; mkdocsConfigFileName?: string; - mkdocsConfigs?: string[]; + mkdocsParameterClean?: boolean; + mkdocsParameterDirty?: boolean; + mkdocsParameterStrict?: boolean; }): Promise => { const port = options.port ?? '8000'; const useDocker = options.useDocker ?? true; @@ -56,7 +58,9 @@ export const runMkdocsServer = async (options: { ...(options.mkdocsConfigFileName ? ['--config-file', options.mkdocsConfigFileName] : []), - ...(options.mkdocsConfigs ?? []), + ...(options.mkdocsParameterClean ? '--clean' : []), + ...(options.mkdocsParameterDirty ? '--dirty' : []), + ...(options.mkdocsParameterStrict ? '--strict' : []), ], { stdoutLogFunc: options.stdoutLogFunc, @@ -74,7 +78,9 @@ export const runMkdocsServer = async (options: { ...(options.mkdocsConfigFileName ? ['--config-file', options.mkdocsConfigFileName] : []), - ...(options.mkdocsConfigs ?? []), + ...(options.mkdocsParameterClean ? '--clean' : []), + ...(options.mkdocsParameterDirty ? '--dirty' : []), + ...(options.mkdocsParameterStrict ? '--strict' : []), ], { stdoutLogFunc: options.stdoutLogFunc,