Created
July 17, 2013 16:21
-
-
Save amatiasq/6022122 to your computer and use it in GitHub Desktop.
A file to load every file found on the same folder or subfolders.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var fs = require("fs"); | |
function scan(dir) { | |
var files = []; | |
fs.readdirSync(dir).forEach(function(file) { | |
var path = dir + '/' + file; | |
var stat = fs.statSync(path); | |
if (stat.isDirectory()) | |
return files.concat(scan(path)); | |
if (stat.isFile()) | |
return files.push(path); | |
}); | |
return files; | |
} | |
scan(__dirname).filter(function(file) { | |
return file !== __filename; | |
}).map(require); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment