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
+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,