Skip to content

Instantly share code, notes, and snippets.

@trezy
Created April 9, 2019 18:13
Show Gist options
  • Save trezy/7203313f55b7bbab0d63d64e4186a92c to your computer and use it in GitHub Desktop.
Save trezy/7203313f55b7bbab0d63d64e4186a92c to your computer and use it in GitHub Desktop.
// Module imports
import fs from 'fs'
import path from 'path'
function exportDirectory (requirePath) {
let exports = {}
for (const filename of fs.readdirSync(requirePath)) {
if (!/^index\./.test(filename)) {
exports = {
...exports,
...require(path.resolve(requirePath, filename)),
}
}
}
return exports
}
export { exportDirectory }
// Module imports
import { exportDirectory } from './exportDirectory'
module.exports = exportDirectory(__dirname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment