Browse Source

use plugin-utils-v4

Yuki Takei 4 years ago
parent
commit
5f278bd1fa

+ 22 - 14
packages/app/bin/generate-plugin-definitions-source.ts

@@ -7,6 +7,8 @@ import fs from 'graceful-fs';
 import normalize from 'normalize-path';
 import normalize from 'normalize-path';
 import swig from 'swig-templates';
 import swig from 'swig-templates';
 
 
+import { PluginDefinitionV4 } from '@growi/core';
+
 import PluginUtils from '../src/server/plugins/plugin-utils';
 import PluginUtils from '../src/server/plugins/plugin-utils';
 import loggerFactory from '../src/utils/logger';
 import loggerFactory from '../src/utils/logger';
 import { resolveFromRoot } from '../src/utils/project-dir-utils';
 import { resolveFromRoot } from '../src/utils/project-dir-utils';
@@ -23,26 +25,32 @@ const OUT = resolveFromRoot('tmp/plugins/plugin-definitions.js');
 const pluginNames: string[] = pluginUtils.listPluginNames();
 const pluginNames: string[] = pluginUtils.listPluginNames();
 logger.info('Detected plugins: ', pluginNames);
 logger.info('Detected plugins: ', pluginNames);
 
 
-// get definitions
-const definitions = pluginNames
-  .map((name) => {
-    return pluginUtils.generatePluginDefinition(name, true);
-  })
-  .map((definition) => {
-    if (definition == null) {
-      return null;
+async function main(): Promise<void> {
+
+  // get definitions
+  const definitions: PluginDefinitionV4[] = [];
+  for (const pluginName of pluginNames) {
+    // eslint-disable-next-line no-await-in-loop
+    const definition = await pluginUtils.generatePluginDefinition(pluginName, true);
+    if (definition != null) {
+      definitions.push(definition);
     }
     }
+  }
 
 
+  definitions.map((definition) => {
     // convert backslash to slash
     // convert backslash to slash
     definition.entries = definition.entries.map((entryPath) => {
     definition.entries = definition.entries.map((entryPath) => {
       return normalize(entryPath);
       return normalize(entryPath);
     });
     });
     return definition;
     return definition;
-  })
-  .filter(definition => definition != null);
+  });
+
+  const compiledTemplate = swig.compileFile(TEMPLATE);
+  const code = compiledTemplate({ definitions });
+
+  // write
+  fs.writeFileSync(OUT, code);
 
 
-const compiledTemplate = swig.compileFile(TEMPLATE);
-const code = compiledTemplate({ definitions });
+}
 
 
-// write
-fs.writeFileSync(OUT, code);
+main();

+ 4 - 2
packages/app/src/client/plugin.js

@@ -29,15 +29,17 @@ export default class GrowiPlugin {
       const meta = definition.meta;
       const meta = definition.meta;
 
 
       switch (meta.pluginSchemaVersion) {
       switch (meta.pluginSchemaVersion) {
-        // v1 is deprecated
+        // v1, v2 and v3 is deprecated
         case 1:
         case 1:
           logger.warn('pluginSchemaVersion 1 is deprecated', definition);
           logger.warn('pluginSchemaVersion 1 is deprecated', definition);
           break;
           break;
-        // v2 is deprecated
         case 2:
         case 2:
           logger.warn('pluginSchemaVersion 2 is deprecated', definition);
           logger.warn('pluginSchemaVersion 2 is deprecated', definition);
           break;
           break;
         case 3:
         case 3:
+          logger.warn('pluginSchemaVersion 2 is deprecated', definition);
+          break;
+        case 4:
           definition.entries.forEach((entry) => {
           definition.entries.forEach((entry) => {
             entry(appContainer);
             entry(appContainer);
           });
           });

+ 1 - 1
packages/app/src/server/crowi/index.js

@@ -427,7 +427,7 @@ Crowi.prototype.start = async function() {
 
 
   // setup plugins
   // setup plugins
   this.pluginService = new PluginService(this, express);
   this.pluginService = new PluginService(this, express);
-  this.pluginService.autoDetectAndLoadPlugins();
+  await 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;
 
 

+ 16 - 11
packages/app/src/server/plugins/plugin.service.js

@@ -12,13 +12,13 @@ class PluginService {
     this.pluginUtils = new PluginUtils();
     this.pluginUtils = new PluginUtils();
   }
   }
 
 
-  autoDetectAndLoadPlugins() {
+  async autoDetectAndLoadPlugins() {
     const isEnabledPlugins = this.crowi.configManager.getConfig('crowi', 'plugin:isEnabledPlugins');
     const isEnabledPlugins = this.crowi.configManager.getConfig('crowi', 'plugin:isEnabledPlugins');
 
 
     // import plugins
     // import plugins
     if (isEnabledPlugins) {
     if (isEnabledPlugins) {
       logger.debug('Plugins are enabled');
       logger.debug('Plugins are enabled');
-      this.loadPlugins(this.pluginUtils.listPluginNames(this.crowi.rootDir));
+      return this.loadPlugins(this.pluginUtils.listPluginNames(this.crowi.rootDir));
     }
     }
 
 
   }
   }
@@ -28,29 +28,34 @@ class PluginService {
    *
    *
    * @memberOf PluginService
    * @memberOf PluginService
    */
    */
-  loadPlugins(pluginNames) {
-    pluginNames
-      .map((name) => {
-        return this.pluginUtils.generatePluginDefinition(name);
-      })
-      .forEach((definition) => {
+  async loadPlugins(pluginNames) {
+    // get definitions
+    const definitions = [];
+    for (const pluginName of pluginNames) {
+      // eslint-disable-next-line no-await-in-loop
+      const definition = await this.pluginUtils.generatePluginDefinition(pluginName);
+      if (definition != null) {
         this.loadPlugin(definition);
         this.loadPlugin(definition);
-      });
+      }
+    }
   }
   }
 
 
   loadPlugin(definition) {
   loadPlugin(definition) {
     const meta = definition.meta;
     const meta = definition.meta;
 
 
     switch (meta.pluginSchemaVersion) {
     switch (meta.pluginSchemaVersion) {
-      // v1 is deprecated
+      // v1, v2 and v3 is deprecated
       case 1:
       case 1:
         logger.warn('pluginSchemaVersion 1 is deprecated', definition);
         logger.warn('pluginSchemaVersion 1 is deprecated', definition);
         break;
         break;
-      // v2 is deprecated
       case 2:
       case 2:
         logger.warn('pluginSchemaVersion 2 is deprecated', definition);
         logger.warn('pluginSchemaVersion 2 is deprecated', definition);
         break;
         break;
       case 3:
       case 3:
+        logger.warn('pluginSchemaVersion 3 is deprecated', definition);
+        break;
+      // v4 or above
+      case 4:
         logger.info(`load plugin '${definition.name}'`);
         logger.info(`load plugin '${definition.name}'`);
         definition.entries.forEach((entryPath) => {
         definition.entries.forEach((entryPath) => {
           const entry = require(entryPath);
           const entry = require(entryPath);

+ 1 - 1
packages/app/src/server/service/app.ts

@@ -119,7 +119,7 @@ class AppService implements S2sMessageHandlable {
   }
   }
 
 
   async setupAfterInstall() {
   async setupAfterInstall() {
-    this.crowi.pluginService.autoDetectAndLoadPlugins();
+    await this.crowi.pluginService.autoDetectAndLoadPlugins();
     this.crowi.setupRoutesAtLast();
     this.crowi.setupRoutesAtLast();
     this.crowi.setupGlobalErrorHandlers();
     this.crowi.setupGlobalErrorHandlers();