Skip to content

Instantly share code, notes, and snippets.

@Aposhian
Created March 3, 2021 01:53
Show Gist options
  • Save Aposhian/ab2ea256913f7d032c59afa6f434a546 to your computer and use it in GitHub Desktop.
Save Aposhian/ab2ea256913f7d032c59afa6f434a546 to your computer and use it in GitHub Desktop.
Autogenerated index.js
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