cleanup: remove unused code in requireDir()

No changes in functionality.
This commit is contained in:
Miroslav Bajtoš 2014-05-27 16:05:43 +02:00
parent 2a619773d4
commit 9930934686
1 changed files with 31 additions and 36 deletions

View File

@ -232,20 +232,13 @@ function forEachKeyedObject(obj, fn) {
});
}
function requireDir(dir, basenames) {
function requireDir(dir) {
assert(dir, 'cannot require directory contents without directory name');
var requires = {};
if (arguments.length === 2) {
// if basenames argument is passed, explicitly include those files
basenames.forEach(function (basename) {
var filepath = path.resolve(path.join(dir, basename));
requires[basename] = tryRequire(filepath);
});
} else if (arguments.length === 1) {
// if basenames arguments isn't passed, require all javascript
// files (except for those prefixed with _) and all directories
// require all javascript files (except for those prefixed with _)
// and all directories
var files = tryReadDir(dir);
@ -265,22 +258,24 @@ function requireDir(dir, basenames) {
files.forEach(function(filename) {
// ignore index.js and files prefixed with underscore
if ((filename === 'index.js') || (filename[0] === '_')) { return; }
if ((filename === 'index.js') || (filename[0] === '_')) {
return;
}
var filepath = path.resolve(path.join(dir, filename));
var ext = path.extname(filename);
var stats = fs.statSync(filepath);
// only require files supported by require.extensions (.txt .md etc.)
if (stats.isFile() && !(ext in require.extensions)) { return; }
if (stats.isFile() && !(ext in require.extensions)) {
return;
}
var basename = path.basename(filename, ext);
requires[basename] = tryRequire(filepath);
});
}
return requires;
}