plugin.service.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const debug = require('debug')('crowi:plugins:PluginService');
  2. const PluginUtils = require('./plugin-utils');
  3. class PluginService {
  4. constructor(crowi, app) {
  5. this.crowi = crowi;
  6. this.app = app;
  7. this.pluginUtils = new PluginUtils();
  8. }
  9. /**
  10. * load plugins
  11. *
  12. * @memberOf PluginService
  13. */
  14. loadPlugins() {
  15. this.pluginUtils.listPluginNames(this.crowi.rootDir)
  16. .map((name) => {
  17. return this.pluginUtils.generatePluginDefinition(name);
  18. })
  19. .forEach((definition) => {
  20. this.loadPlugin(definition);
  21. });
  22. }
  23. loadPlugin(definition) {
  24. const meta = definition.meta;
  25. // v1 is deprecated
  26. if (1 === meta.pluginSchemaVersion) {
  27. debug('pluginSchemaVersion 1 is deprecated');
  28. return;
  29. }
  30. // v2
  31. if (2 === meta.pluginSchemaVersion) {
  32. debug(`load plugin '${definition.name}'`);
  33. definition.entries.forEach((entryPath) => {
  34. const entry = require(entryPath);
  35. entry(this.crowi, this.app);
  36. });
  37. }
  38. }
  39. }
  40. module.exports = PluginService;