Merge pull request #20356 from backstage/custom-mkdocs-config-flag

[TechDocs] enable other file name than mkdocs.yaml
This commit is contained in:
Morgan Bentell
2023-10-09 10:07:02 +02:00
committed by GitHub
9 changed files with 96 additions and 22 deletions
+1
View File
@@ -106,6 +106,7 @@ Options:
-v --verbose
--preview-app-bundle-path <PATH_TO_BUNDLE>
--preview-app-port <PORT>
-c, --mkdocs-config-file-name <FILENAME>
-h, --help
```
@@ -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,
},
);
};