import { Contracts } from "ts-extractor" ; import { Plugin , SupportedApiItemKindType , ApiDefinitionKindAdditional } from "../contracts/plugin" ; export class PluginRegistry { constructor ( ) { for ( const [ , kindValue ] of Object . entries ( Contracts . ApiDefinitionKind ) ) { this . registeredPlugins . set ( kindValue as Contracts . ApiDefinitionKind , [ ] ) ; } } private registeredPlugins : Map < Contracts . ApiDefinitionKind , Plugin [ ] > = new Map ( ) ; private isSupportedKindsHasAny ( kinds ) { return Boolean ( kinds . find ( x => x === ApiDefinitionKindAdditional . Any ) ) ; } public Register ( plugin ) { const supportedKinds = plugin . SupportedApiDefinitionKind ( ) ; if ( this . isSupportedKindsHasAny ( supportedKinds ) ) { for ( const [ key , value ] of this . registeredPlugins ) { this . registeredPlugins . set ( key , [ plugin , ... value ] ) ; } return ; } else { for ( const kind of supportedKinds as Contracts . ApiDefinitionKind [ ] ) { const registeredPluginsOfKind = this . registeredPlugins . get ( kind ) || [ ] ; this . registeredPlugins . set ( kind , [ plugin , ... registeredPluginsOfKind ] ) ; } } } public GetPluginsByKind ( kind ) { return this . registeredPlugins . get ( kind ) || [ ] ; } }