plugin.service.js 1014 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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((entry) => {
  34. entry(this.crowi, this.app);
  35. });
  36. }
  37. }
  38. }
  39. module.exports = PluginService;