Created
July 19, 2015 01:04
-
-
Save reharik/0dea05f448eedcb6326d to your computer and use it in GitHub Desktop.
problem with babel compilation of recursion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var invariant = require('invariant'); | |
var path = require('path'); | |
var helpers = require('./DSLHelpers'); | |
module.exports = (function () { | |
function RegistryDSL() { | |
_classCallCheck(this, RegistryDSL); | |
this.dependencyDeclarations = []; | |
... | |
} | |
_createClass(RegistryDSL, [{ | |
key: 'requireDirectoryRecursively', | |
value: function requireDirectoryRecursively(dir) { | |
var _this2 = this; | |
invariant(dir, 'You must provide a valid directory'); | |
var absoluteDir = path.join(appRoot.path, dir); | |
var result = helpers.recurseDirectories(absoluteDir); | |
console.log(result); // --> returns empty array [] | |
result.forEach(function (x) { | |
return _this2.dependencyDeclarations.push(x); | |
}); | |
return this; | |
} | |
}]); | |
return RegistryDSL; | |
})(); | |
============= | |
var Dependency = require('./Dependency'); | |
var fs = require('fs'); | |
var appRoot = require('./appRoot'); | |
module.exports = { | |
recurseDirectories: function recurseDirectories(dir) { | |
var _this = this; | |
var result = fs.readdirSync(dir).map(function (x) { | |
var stat = fs.statSync(dir + '/' + x); | |
if (stat && stat.isDirectory()) { | |
_this.recurseDirectories(dir + '/' + x); | |
} | |
return x; | |
}).filter(function (x) { | |
return x.endsWith('.js'); | |
}).map(function (x) { | |
return _this.processFile(x, dir); | |
}); | |
console.log(result); // --> returns array full of objects; | |
return result; | |
}, | |
processFile: function processFile(file, dir, groupName) { | |
if (!file.endsWith('.js')) { | |
return; | |
} | |
file = file.replace('.js', ''); | |
var path = dir.replace(appRoot.path, '') + '/' + file; | |
return new Dependency({ name: file, path: path, internal: true, groupName: groupName || '' }); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment