Skip to content

Commit

Permalink
fix: move plugin definition to loadContent() lifecycle (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Dec 7, 2021
1 parent eb289da commit 54104a8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
55 changes: 28 additions & 27 deletions packages/docusaurus-plugin-typedoc/src/plugin.ts
Expand Up @@ -9,46 +9,47 @@ import { PluginOptions } from './types';
// store list of plugin ids when running multiple instances
const apps: string[] = [];

export default async function pluginDocusaurus(
export default function pluginDocusaurus(
context: LoadContext,
opts: Partial<PluginOptions>,
) {
if (opts.id && !apps.includes(opts.id)) {
apps.push(opts.id);

const { siteDir } = context;
return {
name: 'docusaurus-plugin-typedoc',
async loadContent() {
if (opts.id && !apps.includes(opts.id)) {
apps.push(opts.id);

const options = getPluginOptions(opts);
const { siteDir } = context;

const outputDir = path.resolve(siteDir, options.docsRoot, options.out);
const options = getPluginOptions(opts);

removeDir(outputDir);
const outputDir = path.resolve(siteDir, options.docsRoot, options.out);

const app = new Application();
removeDir(outputDir);

app.options.setValue('theme', path.resolve(__dirname));
const app = new Application();

load(app);
app.options.setValue('theme', path.resolve(__dirname));

bootstrap(app, options);
load(app);

const project = app.convert();
bootstrap(app, options);

// if project is undefined typedoc has a problem - error logging will be supplied by typedoc.
if (!project) {
return;
}
const project = app.convert();

if (options.watch) {
app.convertAndWatch(async (project) => {
await app.generateDocs(project, outputDir);
});
} else {
await app.generateDocs(project, outputDir);
}
}
// if project is undefined typedoc has a problem - error logging will be supplied by typedoc.
if (!project) {
return;
}

return {
name: 'docusaurus-plugin-typedoc',
if (options.watch) {
app.convertAndWatch(async (project) => {
await app.generateDocs(project, outputDir);
});
} else {
await app.generateDocs(project, outputDir);
}
}
},
};
}
Expand Up @@ -25,7 +25,7 @@ async function bootstrap(tmpobj: tmp.DirResult, customOptions = {}) {
...customOptions,
},
);
return await plugin;
return await plugin.loadContent();
}

describe(`Plugin:`, () => {
Expand Down

0 comments on commit 54104a8

Please sign in to comment.