fix(techdocs-cli): limit supported mkdocs flags

Signed-off-by: hainenber <dotronghai96@gmail.com>
This commit is contained in:
hainenber
2023-11-20 21:46:41 +07:00
parent 549ca5e3c4
commit 69b2f7bf3b
6 changed files with 35 additions and 9 deletions
+3 -1
View File
@@ -91,7 +91,9 @@ Options:
--docker-option <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> Port for MkDocs server to use (default: "8000")
--preview-app-bundle-path <PATH_TO_BUNDLE> Preview documentation using a web app other than the included one.
--preview-app-port <PORT> Port where the preview will be served.
+3
View File
@@ -107,6 +107,9 @@ Options:
--preview-app-bundle-path <PATH_TO_BUNDLE>
--preview-app-port <PORT>
-c, --mkdocs-config-file-name <FILENAME>
--mkdocs-parameter-clean
--mkdocs-parameter-dirty
--mkdocs-parameter-strict
-h, --help
```
+13 -2
View File
@@ -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 (
@@ -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
@@ -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([
@@ -26,7 +26,9 @@ export const runMkdocsServer = async (options: {
stdoutLogFunc?: LogFunc;
stderrLogFunc?: LogFunc;
mkdocsConfigFileName?: string;
mkdocsConfigs?: string[];
mkdocsParameterClean?: boolean;
mkdocsParameterDirty?: boolean;
mkdocsParameterStrict?: boolean;
}): Promise<ChildProcess> => {
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,