plugin.service.js 895 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. const debug = require('debug')('crowi:plugins:PluginService');
  2. const PluginUtils = require('./plugin-utils');
  3. const PluginLoaderV2 = require('./plugin-loader-v2.model');
  4. class PluginService {
  5. constructor(crowi, app) {
  6. this.crowi = crowi;
  7. this.app = app;
  8. this.pluginUtils = new PluginUtils();
  9. this.pluginLoaderV2 = new PluginLoaderV2();
  10. }
  11. loadPlugins() {
  12. let self = this;
  13. this.pluginUtils.listPluginNames(this.crowi.rootDir)
  14. .map(function(name) {
  15. self.loadPlugin(name);
  16. });
  17. }
  18. loadPlugin(name) {
  19. const meta = require(name);
  20. // v1 is deprecated
  21. if (1 === meta.pluginSchemaVersion) {
  22. debug('pluginSchemaVersion 1 is deprecated');
  23. return;
  24. }
  25. // v2
  26. if (2 === meta.pluginSchemaVersion) {
  27. this.pluginLoaderV2.load(name, this.crowi, this.app);
  28. return;
  29. }
  30. }
  31. }
  32. module.exports = PluginService;