troygoode/node-require-directory — pull request #11 by scharfmedia (2014-07-28 17:20:01+00:00)
Title: allow callback to modify required contents

Use case:
if you do things like this:
// (coffeescript) a example config file in config folder /path/to/configs/my.coffee
module.exports = (opts)->
name: "chris"
environment: if opts.env is “dev” then “development” else “production"

// app code
// goes through every file in the config folder and if it is a function executes it, and returns that instead of the contents.
var opts = {dev: true};
configuration = requireDirectory(module,”/path/to/configs",null,function(err,mod){
return (typeof mod === "function") ? mod(opts) : mod;
});

// results in
configuration.my == {
name: ‘chris’,
environment: ‘development'
};