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');
|
assert(dir, 'cannot require directory contents without directory name');
|
||||||
|
|
||||||
var requires = {};
|
var requires = {};
|
||||||
|
|
||||||
if (arguments.length === 2) {
|
// require all javascript files (except for those prefixed with _)
|
||||||
// if basenames argument is passed, explicitly include those files
|
// and all directories
|
||||||
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
|
|
||||||
|
|
||||||
var files = tryReadDir(dir);
|
var files = tryReadDir(dir);
|
||||||
|
|
||||||
// sort files in lowercase alpha for linux
|
// sort files in lowercase alpha for linux
|
||||||
files.sort(function (a,b) {
|
files.sort(function(a, b) {
|
||||||
a = a.toLowerCase();
|
a = a.toLowerCase();
|
||||||
b = b.toLowerCase();
|
b = b.toLowerCase();
|
||||||
|
|
||||||
if (a < b) {
|
if (a < b) {
|
||||||
return -1;
|
return -1;
|
||||||
} else if (b < a) {
|
} else if (b < a) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
files.forEach(function (filename) {
|
files.forEach(function(filename) {
|
||||||
// ignore index.js and files prefixed with underscore
|
// 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 filepath = path.resolve(path.join(dir, filename));
|
||||||
var ext = path.extname(filename);
|
var ext = path.extname(filename);
|
||||||
var stats = fs.statSync(filepath);
|
var stats = fs.statSync(filepath);
|
||||||
|
|
||||||
// only require files supported by require.extensions (.txt .md etc.)
|
// 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);
|
var basename = path.basename(filename, ext);
|
||||||
|
|
||||||
requires[basename] = tryRequire(filepath);
|
requires[basename] = tryRequire(filepath);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return requires;
|
return requires;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue