Skip to content

Commit

Permalink
feat: TypeDoc 0.21 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Jun 18, 2021
1 parent 52085fa commit 9659567
Show file tree
Hide file tree
Showing 8 changed files with 1,845 additions and 2,709 deletions.
10 changes: 5 additions & 5 deletions packages/docusaurus-plugin-typedoc/package.json
Expand Up @@ -16,20 +16,20 @@
},
"homepage": "https://github.com/tgreyuk/typedoc-plugin-markdown/tree/master/packages/docusaurus-plugin-typedoc",
"peerDependencies": {
"typedoc": ">=0.20.19",
"typedoc-plugin-markdown": ">=3.6.0"
"typedoc": ">=0.21.0",
"typedoc-plugin-markdown": ">=3.10.0"
},
"devDependencies": {
"@docusaurus/types": "^2.0.0-alpha.37"
"@docusaurus/types": "^2.0.0-beta.0"
},
"scripts": {
"lint": "eslint ./src --ext .ts",
"prepublishOnly": "yarn run lint && yarn run build && npm run test",
"prepublishOnly": "yarn run lint && yarn run build && yarn run test",
"build": "rm -rf ./dist && tsc",
"build-and-test": "yarn run build && yarn run test",
"test:init": "rm -rf test/site && npx @docusaurus/init@latest init test/site classic",
"test:demo:start": "yarn run build && cd test/site && yarn run clear && yarn run start",
"test:demo:build": "yarn run build && cd test/site && yarn run clear && yarn run build && yarn run serve",
"test:demo:build": "yarn run build && cd test/site && yarn run clear && yarn run serve",
"test": "jest --colors"
},
"author": "Thomas Grey",
Expand Down
9 changes: 8 additions & 1 deletion packages/docusaurus-plugin-typedoc/src/front-matter.ts
@@ -1,4 +1,5 @@
import * as path from 'path';

import { BindOption } from 'typedoc';
import {
getPageTitle,
Expand All @@ -7,12 +8,15 @@ import {
import { Component } from 'typedoc/dist/lib/converter/components';
import { RendererComponent } from 'typedoc/dist/lib/output/components';
import { PageEvent } from 'typedoc/dist/lib/output/events';

import { FrontMatter, Sidebar } from './types';

@Component({ name: 'front-matter' })
export class FrontMatterComponent extends RendererComponent {
@BindOption('out')
out!: string;
@BindOption('docsRoot')
docsRoot!: string;
@BindOption('sidebar')
sidebar!: Sidebar;
@BindOption('globalsTitle')
Expand Down Expand Up @@ -47,7 +51,10 @@ export class FrontMatterComponent extends RendererComponent {
title: pageTitle,
};
if (page.url === this.entryDocument) {
items = { ...items, slug: '/' + this.out };
items = {
...items,
slug: '/' + path.relative(process.cwd(), this.out),
};
}
if (sidebarLabel && sidebarLabel !== pageTitle) {
items = { ...items, sidebar_label: sidebarLabel };
Expand Down
10 changes: 8 additions & 2 deletions packages/docusaurus-plugin-typedoc/src/options.ts
@@ -1,4 +1,5 @@
import * as path from 'path';

import { PluginOptions } from './types';

const DEFAULT_PLUGIN_OPTIONS: PluginOptions = {
Expand Down Expand Up @@ -31,5 +32,10 @@ export const getPluginOptions = (
return options;
};

export const getOutputDirectory = (siteDir: string, options: PluginOptions) =>
path.resolve(siteDir, options.docsRoot, options.out);
export const getOutputDirectory = (siteDir: string, options: PluginOptions) => {
return path.resolve(
siteDir,
options.docsRoot,
path.relative(process.cwd(), options.out),
);
};
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-typedoc/src/plugin.ts
@@ -1,6 +1,6 @@
import { LoadContext } from '@docusaurus/types';
import { Application } from 'typedoc';
import MarkdownPlugin from 'typedoc-plugin-markdown';
import { load } from 'typedoc-plugin-markdown';

import { getOutputDirectory } from './options';
import { bootstrap } from './render';
Expand All @@ -21,7 +21,7 @@ export default async function pluginDocusaurus(

const app = new Application();

MarkdownPlugin(app);
load(app);

const options = bootstrap(app, opts);

Expand Down
29 changes: 28 additions & 1 deletion packages/docusaurus-plugin-typedoc/src/render.ts
Expand Up @@ -41,7 +41,10 @@ export const bootstrap = (app: Application, opts: Partial<PluginOptions>) => {
};

async function render(project: ProjectReflection, outputDirectory: string) {
if (!this.prepareTheme() || !this.prepareOutputDirectory(outputDirectory)) {
if (
!this.prepareTheme() ||
!isOutputDirectory(this.application, outputDirectory)
) {
return;
}

Expand Down Expand Up @@ -92,6 +95,30 @@ async function render(project: ProjectReflection, outputDirectory: string) {
}
}

const isOutputDirectory = (app: Application, outputDirectory: string) => {
const options = app.options.getRawValues() as PluginOptions;
if (options.disableOutputCheck) {
return true;
}

if (!fs.existsSync(outputDirectory)) {
return true;
}

if (app.renderer.theme!.isOutputDirectory(outputDirectory)) {
if (fs.existsSync(outputDirectory)) {
fs.rmdirSync(outputDirectory, { recursive: true });
}
return true;
} else {
app.logger.error(
`The output directory "${outputDirectory}" exists but does not seem to be a documentation generated by TypeDoc.\n` +
'Make sure this is the right target directory, delete the folder and rerun TypeDoc.',
);
return false;
}
};

const writeCategoryYaml = (
categoryPath: string,
label: string,
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-typedoc/test/site/package.json
Expand Up @@ -12,8 +12,8 @@
"clear": "docusaurus clear"
},
"dependencies": {
"@docusaurus/core": "2.0.0-alpha.75",
"@docusaurus/preset-classic": "2.0.0-alpha.75",
"@docusaurus/core": "2.0.0-beta.0",
"@docusaurus/preset-classic": "2.0.0-beta.0",
"@mdx-js/react": "^1.6.22",
"clsx": "^1.1.1",
"react": "^17.0.2",
Expand Down

0 comments on commit 9659567

Please sign in to comment.