Yuki Takei 6 лет назад
Родитель
Сommit
73ed6e6dbd
3 измененных файлов с 33 добавлено и 29 удалено
  1. 0 15
      src/server/crowi/dev.js
  2. 6 13
      src/server/crowi/index.js
  3. 27 1
      src/server/plugins/plugin.service.js

+ 0 - 15
src/server/crowi/dev.js

@@ -123,21 +123,6 @@ class CrowiDev {
     app.use(require('connect-browser-sync')(bs));
     app.use(require('connect-browser-sync')(bs));
   }
   }
 
 
-  loadPlugins(app) {
-    if (process.env.PLUGIN_NAMES_TOBE_LOADED !== undefined
-        && process.env.PLUGIN_NAMES_TOBE_LOADED.length > 0) {
-      const pluginNames = process.env.PLUGIN_NAMES_TOBE_LOADED.split(',');
-      logger.debug('[development] loading Plugins', pluginNames);
-
-      // merge and remove duplicates
-      if (pluginNames.length > 0) {
-        const PluginService = require('../plugins/plugin.service');
-        const pluginService = new PluginService(this.crowi, app);
-        pluginService.loadPlugins(pluginNames);
-      }
-    }
-  }
-
 }
 }
 
 
 module.exports = CrowiDev;
 module.exports = CrowiDev;

+ 6 - 13
src/server/crowi/index.js

@@ -15,6 +15,8 @@ const mongoose = require('mongoose');
 
 
 const models = require('../models');
 const models = require('../models');
 
 
+const PluginService = require('../plugins/plugin.service');
+
 function Crowi(rootdir) {
 function Crowi(rootdir) {
   const self = this;
   const self = this;
 
 
@@ -363,6 +365,10 @@ Crowi.prototype.start = async function() {
   await this.init();
   await this.init();
   const express = await this.buildServer();
   const express = await this.buildServer();
 
 
+  // setup plugins
+  this.pluginService = new PluginService(this, express);
+  this.pluginService.autoDetectAndLoadPlugins();
+
   const server = (this.node_env === 'development') ? this.crowiDev.setupServer(express) : express;
   const server = (this.node_env === 'development') ? this.crowiDev.setupServer(express) : express;
 
 
   // listen
   // listen
@@ -406,19 +412,6 @@ Crowi.prototype.buildServer = function() {
     express.use(morgan('dev'));
     express.use(morgan('dev'));
   }
   }
 
 
-  // import plugins
-  const isEnabledPlugins = this.configManager.getConfig('crowi', 'plugin:isEnabledPlugins');
-  if (isEnabledPlugins) {
-    debug('Plugins are enabled');
-    const PluginService = require('../plugins/plugin.service');
-    const pluginService = new PluginService(this, express);
-    pluginService.autoDetectAndLoadPlugins();
-
-    if (env === 'development') {
-      this.crowiDev.loadPlugins(express);
-    }
-  }
-
   return Promise.resolve(express);
   return Promise.resolve(express);
 };
 };
 
 

+ 27 - 1
src/server/plugins/plugin.service.js

@@ -10,7 +10,33 @@ class PluginService {
   }
   }
 
 
   autoDetectAndLoadPlugins() {
   autoDetectAndLoadPlugins() {
-    this.loadPlugins(this.pluginUtils.listPluginNames(this.crowi.rootDir));
+    const isEnabledPlugins = this.crowi.configManager.getConfig('crowi', 'plugin:isEnabledPlugins');
+
+    // import plugins
+    if (isEnabledPlugins) {
+      logger.debug('Plugins are enabled');
+      this.loadPlugins(this.pluginUtils.listPluginNames(this.crowi.rootDir));
+
+      // when dev
+      if (this.crowi.node_env === 'development') {
+        this.autoDetectAndLoadPluginsForDev();
+      }
+    }
+
+  }
+
+  autoDetectAndLoadPluginsForDev() {
+    if (process.env.PLUGIN_NAMES_TOBE_LOADED !== undefined
+      && process.env.PLUGIN_NAMES_TOBE_LOADED.length > 0) {
+
+      const pluginNames = process.env.PLUGIN_NAMES_TOBE_LOADED.split(',');
+      logger.debug('[development] loading Plugins', pluginNames);
+
+      // merge and remove duplicates
+      if (pluginNames.length > 0) {
+        this.crowi.pluginService.loadPlugins(pluginNames);
+      }
+    }
   }
   }
 
 
   /**
   /**