import * as path from 'path' ; import { Application , ProjectReflection } from 'typedoc' ; import { load } from 'typedoc-plugin-markdown' ; import { removeDir , render } from './render' ; import { addOptions , getOptions } from './options' ; import { getSidebarJson } from './sidebar' ; import { PluginOptions } from './types' ; let app ; let project ; export const typedocPlugin = ( opts , ctx ) => { const options = getOptions ( opts ) ; return { name : 'vuepress-plugin-typedoc' , async ready ( ) { const outputDirectory = ( ctx . sourceDir || ctx . dir . source ( ) ) + '/' + options . out ; removeDir ( outputDirectory ) ; app = new Application ( ) ; load ( app ) ; addOptions ( app ) ; app . renderer . render = render ; app . bootstrap ( options ) ; project = app . convert ( ) ; if ( ! project ) { return ; } if ( options . watch ) { app . convertAndWatch ( async ( project ) => { await app . generateDocs ( project , outputDirectory ) ; } ) ; } else { await app . generateDocs ( project , outputDirectory ) ; } } , async enhanceAppFiles ( ) { if ( ! app || ! options . sidebar ) { return ; } const theme = app . renderer . theme as any ; const navigation = theme . getNavigation ( project ) ; const sidebarJson = JSON . stringify ( { [ `/${ path . relative ( process . cwd ( ) , options . out ) }/` ] : getSidebarJson ( navigation , options ) , } ) ; return { name : 'typedoc-sidebar' , content : `export default ({ siteData, options }) => {
          siteData.themeConfig.sidebarDepth = 0;
          siteData.themeConfig.sidebar = Object.assign({},siteData.themeConfig.sidebar,${ sidebarJson });
        }` , } ; } , } ; } ;