Skip to content

Instantly share code, notes, and snippets.

@alanhoff
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanhoff/99a1610671ed6ebcbc37 to your computer and use it in GitHub Desktop.
Save alanhoff/99a1610671ed6ebcbc37 to your computer and use it in GitHub Desktop.
index.js
// Load all files inside this folder with a single require
var fs = require('fs');
var str = require('underscore.string');
var files = fs.readdirSync(__dirname);
module.exports = {};
// Iterate over the files that we found, replace the name
// require the file and exports it
files = files.forEach(function(file){
// We don't want an infinite loop
if(file === 'index.js')
return;
var name = str(file.replace(/-model.js/g, '')).chain().camelize().capitalize();
module.exports[name] = require('./' + file);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment