plugin.service.js 881 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. loadPlugins() {
  10. let self = this;
  11. this.pluginUtils.generatePluginDefinitions(this.crowi.rootDir)
  12. .map((definition) => {
  13. self.loadPlugin(definition);
  14. });
  15. }
  16. loadPlugin(definition) {
  17. const meta = definition.meta;
  18. // v1 is deprecated
  19. if (1 === meta.pluginSchemaVersion) {
  20. debug('pluginSchemaVersion 1 is deprecated');
  21. return;
  22. }
  23. // v2
  24. if (2 === meta.pluginSchemaVersion) {
  25. debug(`load plugin '${definition.name}'`);
  26. definition.entries.forEach((entry) => {
  27. entry(this.crowi, this.app);
  28. });
  29. }
  30. }
  31. }
  32. module.exports = PluginService;