Advertisement
Guest User

Untitled

a guest
Aug 5th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. module.exports = class RegistryDSL{
  2. constructor(){
  3.  
  4. this._declarationInProgress;
  5. ...
  6. }
  7.  
  8. requireDirectoryRecursively(dir){
  9. invariant(dir,'You must provide a valid directory');
  10. var absoluteDir= path.join(appRoot.path, dir);
  11. helpers.recurseDirectories(absoluteDir).forEach(x=> this.dependencyDeclarations.push(x));
  12. return this;
  13. }
  14. };
  15.  
  16.  
  17. 'use strict';
  18.  
  19. var Dependency = require('./Dependency');
  20. var fs = require('fs');
  21. var appRoot = require('./appRoot');
  22.  
  23. module.exports = {
  24. recurseDirectories: function recurseDirectories(dir) {
  25. var _this = this;
  26.  
  27. return fs.readdirSync(dir).map(function (x) {
  28. var stat = fs.statSync(dir + '/' + x);
  29. if (stat && stat.isDirectory()) {
  30. _this.recurseDirectories(dir + '/' + x);
  31. }
  32. return x;
  33. }).filter(function (x) {
  34. return x.endsWith('.js');
  35. }).map(function (x) {
  36. return _this.processFile(x, dir);
  37. });
  38. },
  39.  
  40. processFile: function processFile(file, dir, groupName) {
  41. if (!file.endsWith('.js')) {
  42. return;
  43. }
  44. file = file.replace('.js', '');
  45. var path = dir.replace(appRoot.path, '') + '/' + file;
  46. return new Dependency({ name: file, path: path, internal: true, groupName: groupName || '' });
  47. }
  48.  
  49. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement