Handle deleting temportary mkdocs.yml

Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com>
This commit is contained in:
Andre Wanlin
2023-01-25 14:37:01 -06:00
committed by Renan Mendes Carvalho
parent c2bba4affe
commit 37c17ab92c
7 changed files with 45 additions and 14 deletions
@@ -21,6 +21,7 @@ import Docker from 'dockerode';
import {
TechdocsGenerator,
ParsedLocationAnnotation,
getMkDocsYml,
} from '@backstage/plugin-techdocs-node';
import {
ContainerRunner,
@@ -54,6 +55,10 @@ export default async function generate(opts: OptionValues) {
await fs.ensureDir(outputDir);
const { path: mkDocsYmlPath, configIsTemporary } = await getMkDocsYml(
sourceDir,
);
const config = new ConfigReader({
techdocs: {
generator: {
@@ -109,5 +114,11 @@ export default async function generate(opts: OptionValues) {
siteOptions: { name: opts.siteName },
});
if (configIsTemporary) {
process.on('exit', async () => {
fs.rmSync(mkDocsYmlPath, {});
});
}
logger.info('Done!');
}
@@ -19,7 +19,8 @@ import openBrowser from 'react-dev-utils/openBrowser';
import { createLogger } from '../../lib/utility';
import { runMkdocsServer } from '../../lib/mkdocsServer';
import { LogFunc, waitForSignal } from '../../lib/run';
import { getMkdocsYml } from '@backstage/plugin-techdocs-node';
import { getMkDocsYml } from '@backstage/plugin-techdocs-node';
import fs from 'fs-extra';
export default async function serveMkdocs(opts: OptionValues) {
const logger = createLogger({ verbose: opts.verbose });
@@ -28,7 +29,10 @@ export default async function serveMkdocs(opts: OptionValues) {
const localAddr = `http://127.0.0.1:${opts.port}`;
const expectedDevAddr = opts.docker ? dockerAddr : localAddr;
await getMkdocsYml('./', opts.siteName);
const { path: mkDocsYmlPath, configIsTemporary } = await getMkDocsYml(
'./',
opts.siteName,
);
// We want to open browser only once based on a log.
let boolOpenBrowserTriggered = false;
@@ -74,4 +78,10 @@ export default async function serveMkdocs(opts: OptionValues) {
// Keep waiting for user to cancel the process
await waitForSignal([childProcess]);
if (configIsTemporary) {
process.on('exit', async () => {
fs.rmSync(mkDocsYmlPath, {});
});
}
}
@@ -22,7 +22,8 @@ import HTTPServer from '../../lib/httpServer';
import { runMkdocsServer } from '../../lib/mkdocsServer';
import { LogFunc, waitForSignal } from '../../lib/run';
import { createLogger } from '../../lib/utility';
import { getMkdocsYml } from '@backstage/plugin-techdocs-node';
import { getMkDocsYml } from '@backstage/plugin-techdocs-node';
import fs from 'fs-extra';
function findPreviewBundlePath(): string {
try {
@@ -65,7 +66,10 @@ export default async function serve(opts: OptionValues) {
? mkdocsDockerAddr
: mkdocsLocalAddr;
await getMkdocsYml('./', opts.siteName);
const { path: mkDocsYmlPath, configIsTemporary } = await getMkDocsYml(
'./',
opts.siteName,
);
let mkdocsServerHasStarted = false;
const mkdocsLogFunc: LogFunc = data => {
@@ -143,4 +147,10 @@ export default async function serve(opts: OptionValues) {
});
await waitForSignal([mkdocsChildProcess]);
if (configIsTemporary) {
process.on('exit', async () => {
fs.rmSync(mkDocsYmlPath, {});
});
}
}