Created
August 4, 2014 13:09
-
-
Save barneycarroll/dae9b1b48ce0fb74903d to your computer and use it in GitHub Desktop.
Supply a path to return an object with all that path's JS modules exports as properties / methods of the returned object.
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
var fs = require( 'fs' ); | |
var path = require( 'path' ); | |
module.exports = function( folder ){ | |
var output = {}; | |
fs.readdirSync( folder ) | |
.filter( function isJavascript( filename ){ | |
return '.js' === path.extname( filename ); | |
} ) | |
.forEach( function addModuleToOutput( filename ){ | |
var key = path.basename( filename, path.extname( filename ) ); | |
output[ key ] = require( folder + filename ); | |
} ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment