Handle deleting temportary mkdocs.yml
Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com>
This commit is contained in:
committed by
Renan Mendes Carvalho
parent
c2bba4affe
commit
37c17ab92c
@@ -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, {});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import { ParsedLocationAnnotation } from '../../helpers';
|
||||
import {
|
||||
createOrUpdateMetadata,
|
||||
getGeneratorKey,
|
||||
getMkdocsYml,
|
||||
getMkDocsYml,
|
||||
getRepoUrlFromLocationAnnotation,
|
||||
patchIndexPreBuild,
|
||||
storeEtagMetadata,
|
||||
@@ -517,7 +517,7 @@ describe('helpers', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getMkdocsYml', () => {
|
||||
describe('getMkDocsYml', () => {
|
||||
const inputDir = resolvePath(__filename, '../__fixtures__/');
|
||||
const siteOptions = {
|
||||
name: mockEntity.metadata.title,
|
||||
@@ -530,7 +530,7 @@ describe('helpers', () => {
|
||||
path: mkdocsPath,
|
||||
content,
|
||||
configIsTemporary,
|
||||
} = await getMkdocsYml(inputDir, siteOptions);
|
||||
} = await getMkDocsYml(inputDir, siteOptions);
|
||||
|
||||
expect(mkdocsPath).toBe(key);
|
||||
expect(content).toBe(mkdocsYml.toString());
|
||||
@@ -544,7 +544,7 @@ describe('helpers', () => {
|
||||
path: mkdocsPath,
|
||||
content,
|
||||
configIsTemporary,
|
||||
} = await getMkdocsYml(inputDir, siteOptions);
|
||||
} = await getMkDocsYml(inputDir, siteOptions);
|
||||
expect(mkdocsPath).toBe(key);
|
||||
expect(content).toBe(mkdocsYml.toString());
|
||||
expect(configIsTemporary).toBe(false);
|
||||
@@ -562,7 +562,7 @@ describe('helpers', () => {
|
||||
path: mkdocsPath,
|
||||
content,
|
||||
configIsTemporary,
|
||||
} = await getMkdocsYml(inputDir, defaultSiteOptions);
|
||||
} = await getMkDocsYml(inputDir, defaultSiteOptions);
|
||||
|
||||
expect(mkdocsPath).toBe(key);
|
||||
expect(content).toBe(mkdocsDefaultYml.toString());
|
||||
@@ -571,7 +571,7 @@ describe('helpers', () => {
|
||||
|
||||
it('throws when neither .yml nor .yaml nor default file is present', async () => {
|
||||
const invalidInputDir = resolvePath(__filename);
|
||||
await expect(getMkdocsYml(invalidInputDir, siteOptions)).rejects.toThrow(
|
||||
await expect(getMkDocsYml(invalidInputDir, siteOptions)).rejects.toThrow(
|
||||
/Could not read MkDocs YAML config file mkdocs.yml or mkdocs.yaml or default for validation/,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -193,7 +193,7 @@ export const generateMkdocsYml = async (
|
||||
* @param siteOptions - options for the site: `name` property will be used in mkdocs.yml for the
|
||||
* required `site_name` property, default value is "Documentation Site"
|
||||
*/
|
||||
export const getMkdocsYml = async (
|
||||
export const getMkDocsYml = async (
|
||||
inputDir: string,
|
||||
siteOptions?: { name?: string },
|
||||
): Promise<{ path: string; content: string; configIsTemporary: boolean }> => {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
export { TechdocsGenerator } from './techdocs';
|
||||
export { Generators } from './generators';
|
||||
export { getMkdocsYml } from './helpers';
|
||||
export { getMkDocsYml } from './helpers';
|
||||
export type {
|
||||
GeneratorBase,
|
||||
GeneratorOptions,
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
} from '@backstage/integration';
|
||||
import {
|
||||
createOrUpdateMetadata,
|
||||
getMkdocsYml,
|
||||
getMkDocsYml,
|
||||
patchIndexPreBuild,
|
||||
runCommand,
|
||||
storeEtagMetadata,
|
||||
@@ -100,7 +100,7 @@ export class TechdocsGenerator implements GeneratorBase {
|
||||
} = options;
|
||||
|
||||
// Do some updates to mkdocs.yml before generating docs e.g. adding repo_url
|
||||
const { path: mkdocsYmlPath, content } = await getMkdocsYml(
|
||||
const { path: mkdocsYmlPath, content } = await getMkDocsYml(
|
||||
inputDir,
|
||||
siteOptions,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user