aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/plugins/plugin-manager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/plugins/plugin-manager.ts')
-rw-r--r--server/lib/plugins/plugin-manager.ts34
1 files changed, 30 insertions, 4 deletions
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts
index 7cbfa8569..8496979f8 100644
--- a/server/lib/plugins/plugin-manager.ts
+++ b/server/lib/plugins/plugin-manager.ts
@@ -11,6 +11,7 @@ import { PLUGIN_GLOBAL_CSS_PATH } from '../../initializers/constants'
11import { PluginType } from '../../../shared/models/plugins/plugin.type' 11import { PluginType } from '../../../shared/models/plugins/plugin.type'
12import { installNpmPlugin, installNpmPluginFromDisk, removeNpmPlugin } from './yarn' 12import { installNpmPlugin, installNpmPluginFromDisk, removeNpmPlugin } from './yarn'
13import { outputFile } from 'fs-extra' 13import { outputFile } from 'fs-extra'
14import { ServerConfigPlugin } from '../../../shared/models/server'
14 15
15export interface RegisteredPlugin { 16export interface RegisteredPlugin {
16 name: string 17 name: string
@@ -47,7 +48,7 @@ export class PluginManager {
47 private constructor () { 48 private constructor () {
48 } 49 }
49 50
50 async registerPlugins () { 51 async registerPluginsAndThemes () {
51 await this.resetCSSGlobalFile() 52 await this.resetCSSGlobalFile()
52 53
53 const plugins = await PluginModel.listEnabledPluginsAndThemes() 54 const plugins = await PluginModel.listEnabledPluginsAndThemes()
@@ -63,12 +64,20 @@ export class PluginManager {
63 this.sortHooksByPriority() 64 this.sortHooksByPriority()
64 } 65 }
65 66
67 getRegisteredPluginOrTheme (name: string) {
68 return this.registeredPlugins[name]
69 }
70
66 getRegisteredPlugin (name: string) { 71 getRegisteredPlugin (name: string) {
67 return this.registeredPlugins[ name ] 72 const registered = this.getRegisteredPluginOrTheme(name)
73
74 if (!registered || registered.type !== PluginType.PLUGIN) return undefined
75
76 return registered
68 } 77 }
69 78
70 getRegisteredTheme (name: string) { 79 getRegisteredTheme (name: string) {
71 const registered = this.getRegisteredPlugin(name) 80 const registered = this.getRegisteredPluginOrTheme(name)
72 81
73 if (!registered || registered.type !== PluginType.THEME) return undefined 82 if (!registered || registered.type !== PluginType.THEME) return undefined
74 83
@@ -76,7 +85,11 @@ export class PluginManager {
76 } 85 }
77 86
78 getRegisteredPlugins () { 87 getRegisteredPlugins () {
79 return this.registeredPlugins 88 return this.getRegisteredPluginsOrThemes(PluginType.PLUGIN)
89 }
90
91 getRegisteredThemes () {
92 return this.getRegisteredPluginsOrThemes(PluginType.THEME)
80 } 93 }
81 94
82 async runHook (hookName: string, param?: any) { 95 async runHook (hookName: string, param?: any) {
@@ -309,6 +322,19 @@ export class PluginManager {
309 } 322 }
310 } 323 }
311 324
325 private getRegisteredPluginsOrThemes (type: PluginType) {
326 const plugins: RegisteredPlugin[] = []
327
328 for (const pluginName of Object.keys(this.registeredPlugins)) {
329 const plugin = this.registeredPlugins[ pluginName ]
330 if (plugin.type !== type) continue
331
332 plugins.push(plugin)
333 }
334
335 return plugins
336 }
337
312 static get Instance () { 338 static get Instance () {
313 return this.instance || (this.instance = new this()) 339 return this.instance || (this.instance = new this())
314 } 340 }