Skip to content

Instantly share code, notes, and snippets.

@adriancmiranda
Last active March 20, 2016 03:17
Show Gist options
  • Select an option

  • Save adriancmiranda/670b2928385a29a7664c to your computer and use it in GitHub Desktop.

Select an option

Save adriancmiranda/670b2928385a29a7664c to your computer and use it in GitHub Desktop.
var fs = require('fs')
var path = require('path')
fs.readdirSync(__dirname).forEach(function(file){
var pathArray = file.split('/')
var hasIndex = ~file.indexOf('index.js')
if(pathArray.length === 1 && !hasIndex){
var fileName = pathArray[pathArray.length - 1].replace('.js', '')
module.exports[fileName] = require(path.join(__dirname, file))
}else if(pathArray.length === 2 && hasIndex){
var packName = pathArray[pathArray.length - 2];
module.exports[packName] = module.exports[packName] || {};
module.exports[packName] = require(path.join(__dirname, file))
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment