You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

42 lines
961 B

  1. let fileLister = require('../misc/fileLister');
  2. let events = require('../misc/events');
  3. let pathUtilities = require('path');
  4. let onReady = null;
  5. module.exports = {
  6. components: {},
  7. init: function (callback) {
  8. onReady = callback;
  9. events.emit('onBeforeGetComponents', this.components);
  10. this.getComponentFolder();
  11. },
  12. getComponentFolder: function () {
  13. let files = fileLister.getFolder('./components/');
  14. files = files.filter(w => (
  15. (w.indexOf('components') === -1) &&
  16. (w.indexOf('cpnBase') === -1) &&
  17. (w.indexOf('projectile') === -1)
  18. ));
  19. let fLen = files.length;
  20. for (let i = 0; i < fLen; i++)
  21. this.getComponentFile(`./${files[i]}`);
  22. onReady();
  23. },
  24. getComponentFile: function (path) {
  25. let fileName = pathUtilities.basename(path);
  26. fileName = fileName.replace('.js', '');
  27. let cpn = require(path);
  28. this.onGetComponent(cpn);
  29. },
  30. onGetComponent: function (template) {
  31. this.components[template.type] = template;
  32. }
  33. };