print the mkdocs output when running the generate command with the --verbose flag

Signed-off-by: Morgan Bentell <mbentell@spotify.com>
This commit is contained in:
Morgan Bentell
2023-02-22 17:18:35 +01:00
parent f16d9f31cd
commit 8e465ce52e
3 changed files with 23 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@techdocs/cli': minor
---
Running `@techdocs/cli generate` with the `--verbose` flag will now print the mkdocs output.
@@ -31,8 +31,8 @@ import { ConfigReader } from '@backstage/config';
import {
convertTechDocsRefToLocationAnnotation,
createLogger,
getLogStream,
} from '../../lib/utility';
import { stdout } from 'process';
export default async function generate(opts: OptionValues) {
// Use techdocs-node package to generate docs. Keep consistency between Backstage and CI generating docs.
@@ -110,7 +110,7 @@ export default async function generate(opts: OptionValues) {
: {}),
logger,
etag: opts.etag,
...(process.env.LOG_LEVEL === 'debug' ? { logStream: stdout } : {}),
logStream: getLogStream(logger),
siteOptions: { name: opts.siteName },
});
+16
View File
@@ -18,6 +18,8 @@ import {
ParsedLocationAnnotation,
} from '@backstage/plugin-techdocs-node';
import * as winston from 'winston';
import { Writable } from 'stream';
import { stdout } from 'process';
export const convertTechDocsRefToLocationAnnotation = (
techdocsRef: string,
@@ -52,3 +54,17 @@ export const createLogger = ({
return logger;
};
export const getLogStream = (logger: winston.Logger): Writable => {
if (process.env.LOG_LEVEL === 'debug') {
return stdout;
}
return new Writable({
defaultEncoding: 'utf8',
write(chunk, _encoding, next) {
logger.verbose(chunk.toString().trim());
next();
},
});
};