Created
May 30, 2015 01:56
-
-
Save rxw1/2b253ca56d1b44ee7627 to your computer and use it in GitHub Desktop.
Require all javascript files in a directory and export them by their file name
This file contains 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
'use strict'; | |
let fs = require('fs'); | |
let path = require('path'); | |
function excludeFiles(file) { | |
return (file.indexOf('.') !== 0) && | |
(file !== 'index.js'); | |
} | |
function exportFiles(file) { | |
let f = path.basename(file, '.js'); | |
exports[f] = require('./' + f); | |
} | |
fs.readdirSync(__dirname) | |
.filter(excludeFiles) | |
.forEach(exportFiles); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment