2
0

plugin-utils-v2.js 891 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const path = require('path');
  2. class PluginUtilsV2 {
  3. /**
  4. * return a definition objects that has following structure:
  5. *
  6. * {
  7. * name: 'crowi-plugin-X',
  8. * meta: require('crowi-plugin-X'),
  9. * entries: [
  10. * 'crowi-plugin-X/lib/client-entry'
  11. * ]
  12. * }
  13. *
  14. *
  15. * @param {string} pluginName
  16. * @return
  17. * @memberOf PluginService
  18. */
  19. generatePluginDefinition(name, isForClient = false) {
  20. const meta = require(name);
  21. let entries = (isForClient) ? meta.clientEntries : meta.serverEntries;
  22. entries = entries.map((entryPath) => {
  23. const moduleRoot = path.resolve(require.resolve(`${name}/package.json`), '..');
  24. const entryRelativePath = path.relative(moduleRoot, entryPath);
  25. return path.join(name, entryRelativePath);
  26. });
  27. return {
  28. name,
  29. meta,
  30. entries,
  31. }
  32. }
  33. }
  34. module.exports = PluginUtilsV2