Permalink
Browse files

Now requires subdirectories too

  • Loading branch information...
1 parent 649bf56 commit 2bff02d56a407796699a30f2c68dbac225a03c01 @fent fent committed Dec 20, 2011
Showing with 12 additions and 4 deletions.
  1. +12 −4 index.js
View
@@ -5,11 +5,19 @@ module.exports = function requireAll(options) {
var modules = {};
files.forEach(function(file) {
- var match = file.match(options.filter);
- if (!match) return;
+ var filepath = options.dirname + '/' + file;
+ if (fs.statSync(filepath).isDirectory()) {
+ modules[file] = requireAll({
+ dirname: filepath,
+ filter: options.filter
+ });
- var moduleName = match[1];
- modules[moduleName] = require(options.dirname + '/' + moduleName);
+ } else {
+ var match = file.match(options.filter);
+ if (!match) return;
+
+ modules[match[1]] = require(filepath);
+ }
});
return modules;

0 comments on commit 2bff02d

Please sign in to comment.