Created
October 2, 2011 16:59
-
-
Save nanodeath/1257631 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
fs = require 'fs' | |
path = require 'path' | |
isDirectory = (base, p) -> | |
fullPath = path.resolve base, p | |
fs.statSync(fullPath).isDirectory() | |
mergeExports = (theExports, otherModule) -> | |
for otherExport, func of otherModule | |
theExports[otherExport] = otherModule[otherExport] | |
loadDirectory = (directory, recursive=true) -> | |
blacklist = [] | |
files = fs.readdirSync directory | |
theExports = {} | |
for file in files | |
if blacklist.indexOf(file) < 0 | |
if isDirectory(directory, file) | |
mergeExports(theExports, loadDirectory(file)) if recursive | |
else if path.extname(file) == ".coffee" | |
fullPath = path.resolve path.join(directory, path.basename(file, ".coffee")) | |
mergeExports(theExports, require(fullPath)) | |
theExports | |
module.exports = loadDirectory |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment