Skip to content

Commit

Permalink
fix: watch mode compatibility (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Jan 5, 2022
1 parent 5353334 commit da65f74
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions packages/typedoc-plugin-markdown/src/index.ts
@@ -1,6 +1,11 @@
import * as path from 'path';

import { Application, ParameterType } from 'typedoc';
import {
Application,
ParameterType,
ProjectReflection,
RendererEvent,
} from 'typedoc';

import { CustomOptionsReader } from './options-reader';
import { MarkdownTheme } from './theme';
Expand Down Expand Up @@ -75,15 +80,16 @@ function addDeclarations(app: Application) {

function loadTheme(app: Application) {
const themeRef = app.options.getValue('theme');

if (['default', 'markdown'].includes(themeRef)) {
app.renderer.render = render;
app.renderer.theme = new MarkdownTheme(app.renderer);
} else {
const CustomTheme = getCustomTheme(
path.resolve(path.join(themeRef, 'theme.js')),
);
if (CustomTheme !== null) {
app.options.addReader(new CustomOptionsReader());
app.renderer.render = render;
app.renderer.theme = new CustomTheme(app.renderer);
} else {
app.logger.warn(
Expand All @@ -93,6 +99,28 @@ function loadTheme(app: Application) {
}
}

async function render(project: ProjectReflection, outputDirectory: string) {
const output = new RendererEvent(
RendererEvent.BEGIN,
outputDirectory,
project,
);
if (
!this.prepareTheme() ||
!(await this.prepareOutputDirectory(outputDirectory))
) {
return;
}
output.urls = this.theme!.getUrls(project);
this.trigger(output);
if (!output.isDefaultPrevented) {
output?.urls?.forEach((mapping) => {
this.renderDocument(output.createPageEvent(mapping));
});
this.trigger(RendererEvent.END, output);
}
}

function getCustomTheme(themeFile: string) {
try {
const ThemeClass = require(themeFile);
Expand Down

0 comments on commit da65f74

Please sign in to comment.