Skip to content

Instantly share code, notes, and snippets.

@reggi
Created March 17, 2014 16:15
Show Gist options
  • Save reggi/9602437 to your computer and use it in GitHub Desktop.
Save reggi/9602437 to your computer and use it in GitHub Desktop.
Requires every file in a directory into a single object.
var fs = require("fs");
var _ = require("underscore");
var dotty = require("dotty");
module.exports = function() {
var files = fs.readdirSync(__dirname);
files = _.difference(files, ["index.js", ".DS_Store"]);
var result = {};
_.each(files, function(value) {
var pieces = _.without(value.split("."), "js");
var value = require("./" + value);
dotty.put(result, pieces, value);
});
return result;
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment