import Immutable from "immutable" ; import TemplateBlock from "./templateBlock" ; import PluginDependency from "./pluginDependency" ; import THEME_PREFIX from "../constants/themePrefix" ; const DEFAULT_VERSION = "*" ; type Content = Immutable . Map < any , any > ; type Package = Immutable . Map < any , any > ; class Plugin extends Immutable . Record ( { name : String ( ) , version : String ( DEFAULT_VERSION ) , path : String ( ) , depth : Number ( 0 ) , parent : String ( ) , package : Immutable . Map ( ) , content : Immutable . Map ( ) , } , "Plugin" ) { getName ( ) { return this . get ( "name" ) ; } getPath ( ) { return this . get ( "path" ) ; } getVersion ( ) { return this . get ( "version" ) ; } getPackage ( ) { return this . get ( "package" ) ; } getContent ( ) { return this . get ( "content" ) ; } getDepth ( ) { return this . get ( "depth" ) ; } getParent ( ) { return this . get ( "parent" ) ; } return { string } getNpmID ( ) { return PluginDependency . nameToNpmID ( this . getName ( ) ) ; } return { boolean } isLoaded ( ) { return Boolean ( this . getPackage ( ) . size > 0 ) ; } return { boolean } isTheme ( ) { const name = this . getName ( ) ; return name && name . indexOf ( THEME_PREFIX ) === 0 ; } /**
     * Return map of hooks
     */ getHooks ( ) { return this . getContent ( ) . get ( "hooks" ) || Immutable . Map ( ) ; } param { string } type return { Map < String getResources ( type ) { if ( type != "website" && type != "ebook" ) { throw new Error ( `Invalid assets type ${ type }` ) ; } const content = this . getContent ( ) ; return content . get ( type ) || ( type == "website" ? content . get ( "book" ) : null ) || Immutable . Map ( ) ; } return { Map < String getFilters ( ) { return this . getContent ( ) . get ( "filters" ) ; } return { Map < String getBlocks ( ) { let blocks = this . getContent ( ) . get ( "blocks" ) ; blocks = blocks || Immutable . Map ( ) ; return blocks . map ( ( block , blockName ) => { return TemplateBlock . create ( blockName , block ) ; } ) ; } param { string } name return { Function | undefined } getHook ( name ) { return this . getHooks ( ) . get ( name ) ; } param { string } return { Plugin } static createFromString ( s ) { const parts = s . split ( "@" ) ; const name = parts [ 0 ] ; const version = parts . slice ( 1 ) . join ( "@" ) ; return new Plugin ( { name : name , version : version || DEFAULT_VERSION , } ) ; } return { Plugin } static createFromDep ( dep ) { return new Plugin ( { name : dep . getName ( ) , version : dep . getVersion ( ) , } ) ; } static nameToNpmID = PluginDependency . nameToNpmID ; } export default Plugin ;