Last active
March 20, 2016 03:17
-
-
Save adriancmiranda/670b2928385a29a7664c to your computer and use it in GitHub Desktop.
This file contains hidden or 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') | |
| 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