import { LoadContext } from '@docusaurus/types' ; import * as path from 'path' ; import { Application } from 'typedoc' ; import { load } from 'typedoc-plugin-markdown' ; import { getPluginOptions } from './options' ; import { bootstrap , removeDir } from './render' ; import { DocusaurusTheme } from './theme' ; import { PluginOptions } from './types' ; const apps = [ ] ; export default function pluginDocusaurus ( context , opts ) { return { name : 'docusaurus-plugin-typedoc' , async loadContent ( ) { if ( opts . id && ! apps . includes ( opts . id ) ) { apps . push ( opts . id ) ; const { siteDir } = context ; const options = getPluginOptions ( opts ) ; const outputDir = path . resolve ( siteDir , options . docsRoot , options . out ) ; removeDir ( outputDir ) ; const app = new Application ( ) ; app . renderer . defineTheme ( 'docusaurus' , DocusaurusTheme ) ; load ( app ) ; bootstrap ( app , options ) ; const project = app . convert ( ) ; if ( ! project ) { return ; } if ( options . watch ) { app . convertAndWatch ( async ( project ) => { await app . generateDocs ( project , outputDir ) ; } ) ; } else { await app . generateDocs ( project , outputDir ) ; } } } , } ; }