Created
March 3, 2021 01:53
-
-
Save Aposhian/ab2ea256913f7d032c59afa6f434a546 to your computer and use it in GitHub Desktop.
Autogenerated index.js
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
const path = require('path') | |
const fs = require('fs') | |
const files = fs.readdirSync(path.dirname('.')) | |
const toFunctionName = (str) => str.replace( | |
/([-_][a-z])/g, | |
(group) => group.toUpperCase() | |
.replace('-', '') | |
.replace('_', '') | |
).replace('.js', '') | |
module.exports = files.reduce((acc, file) => { | |
if (file !== 'index.js') { | |
const stats = fs.statSync(file) | |
if (stats.isFile()) { | |
acc[toFunctionName(file)] = require(`./${file}`).handler | |
} | |
} | |
return acc | |
}, {}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment