cleanup: remove unused code in requireDir()
No changes in functionality.
This commit is contained in:
parent
2a619773d4
commit
9930934686
67
index.js
67
index.js
|
@ -232,54 +232,49 @@ 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);
|
||||
var files = tryReadDir(dir);
|
||||
|
||||
// sort files in lowercase alpha for linux
|
||||
files.sort(function (a,b) {
|
||||
a = a.toLowerCase();
|
||||
b = b.toLowerCase();
|
||||
// sort files in lowercase alpha for linux
|
||||
files.sort(function(a, b) {
|
||||
a = a.toLowerCase();
|
||||
b = b.toLowerCase();
|
||||
|
||||
if (a < b) {
|
||||
return -1;
|
||||
} else if (b < a) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
if (a < b) {
|
||||
return -1;
|
||||
} else if (b < a) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
files.forEach(function (filename) {
|
||||
// ignore index.js and files prefixed with underscore
|
||||
if ((filename === 'index.js') || (filename[0] === '_')) { return; }
|
||||
files.forEach(function(filename) {
|
||||
// ignore index.js and files prefixed with underscore
|
||||
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);
|
||||
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; }
|
||||
// only require files supported by require.extensions (.txt .md etc.)
|
||||
if (stats.isFile() && !(ext in require.extensions)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var basename = path.basename(filename, ext);
|
||||
var basename = path.basename(filename, ext);
|
||||
|
||||
requires[basename] = tryRequire(filepath);
|
||||
});
|
||||
|
||||
}
|
||||
requires[basename] = tryRequire(filepath);
|
||||
});
|
||||
|
||||
return requires;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue