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.
25 lines
545 B
25 lines
545 B
var fs = require('fs');
|
|
|
|
module.exports = function requireAll(options) {
|
|
var files = fs.readdirSync(options.dirname);
|
|
var modules = {};
|
|
|
|
files.forEach(function(file) {
|
|
var filepath = options.dirname + '/' + file;
|
|
if (fs.statSync(filepath).isDirectory()) {
|
|
modules[file] = requireAll({
|
|
dirname: filepath,
|
|
filter: options.filter
|
|
});
|
|
|
|
} else {
|
|
var match = file.match(options.filter);
|
|
if (!match) return;
|
|
|
|
modules[match[1]] = require(filepath);
|
|
}
|
|
});
|
|
|
|
return modules;
|
|
};
|
|
|