add --mkdocs-config-file-name cli argument to the techdocs-cli serve command

Signed-off-by: Morgan Bentell <mbentell@spotify.com>
This commit is contained in:
Morgan Bentell
2023-10-04 12:08:52 +02:00
parent 73083595bc
commit d06b30b050
6 changed files with 93 additions and 20 deletions
@@ -285,6 +285,10 @@ export function registerCommands(program: Command) {
'Port for the preview app to be served on',
defaultPreviewAppPort,
)
.option(
'-c, --mkdocs-config-file-name <FILENAME>',
'Mkdocs config file name',
)
.hook('preAction', command => {
if (
command.opts().previewAppPort !== defaultPreviewAppPort &&
@@ -65,11 +65,13 @@ export default async function serve(opts: OptionValues) {
const mkdocsExpectedDevAddr = opts.docker
? mkdocsDockerAddr
: mkdocsLocalAddr;
const mkdocsConfigFileName = opts.mkdocsConfigFileName;
const siteName = opts.siteName;
const { path: mkdocsYmlPath, configIsTemporary } = await getMkdocsYml(
'./',
opts.siteName,
);
const { path: mkdocsYmlPath, configIsTemporary } = await getMkdocsYml('./', {
name: siteName,
mkdocsConfigFileName,
});
let mkdocsServerHasStarted = false;
const mkdocsLogFunc: LogFunc = data => {
@@ -104,6 +106,7 @@ export default async function serve(opts: OptionValues) {
useDocker: opts.docker,
stdoutLogFunc: mkdocsLogFunc,
stderrLogFunc: mkdocsLogFunc,
mkdocsConfigFileName: mkdocsYmlPath,
});
// Wait until mkdocs server has started so that Backstage starts with docs loaded
+19 -4
View File
@@ -25,6 +25,7 @@ export const runMkdocsServer = async (options: {
dockerOptions?: string[];
stdoutLogFunc?: LogFunc;
stderrLogFunc?: LogFunc;
mkdocsConfigFileName?: string;
}): Promise<ChildProcess> => {
const port = options.port ?? '8000';
const useDocker = options.useDocker ?? true;
@@ -51,6 +52,9 @@ export const runMkdocsServer = async (options: {
'serve',
'--dev-addr',
`0.0.0.0:${port}`,
...(options.mkdocsConfigFileName
? ['--config-file', options.mkdocsConfigFileName]
: []),
],
{
stdoutLogFunc: options.stdoutLogFunc,
@@ -59,8 +63,19 @@ export const runMkdocsServer = async (options: {
);
}
return await run('mkdocs', ['serve', '--dev-addr', `127.0.0.1:${port}`], {
stdoutLogFunc: options.stdoutLogFunc,
stderrLogFunc: options.stderrLogFunc,
});
return await run(
'mkdocs',
[
'serve',
'--dev-addr',
`127.0.0.1:${port}`,
...(options.mkdocsConfigFileName
? ['--config-file', options.mkdocsConfigFileName]
: []),
],
{
stdoutLogFunc: options.stdoutLogFunc,
stderrLogFunc: options.stderrLogFunc,
},
);
};