Skip to content

Instantly share code, notes, and snippets.

@prakashsellathurai
Last active September 1, 2018 16:44
Show Gist options
  • Save prakashsellathurai/e02efa9bdaad1d0f60205a9a17deaea3 to your computer and use it in GitHub Desktop.
Save prakashsellathurai/e02efa9bdaad1d0f60205a9a17deaea3 to your computer and use it in GitHub Desktop.
BETTER WAY TO EXPORT THE CLOUD FUNCTIONS BY WRAPPING IT UNDER DIRECTORY IN HIERARCHIAL NAMING SCHEMA
const glob = require('glob')
function exportFunction () {
return glob.sync('{,!(node_modules)/**/}*.js', { cwd: __dirname }).forEach(file => {
const only = process.env.FUNCTION_NAME
const name = concoctFunctionName(file)
if (only === undefined || only === name) {
console.log(name + '' + 'file: ' + file)
}
})
}
function concoctFunctionName (file) {
const camel = require('camelcase')
const split = file.split('/')
const event = split.pop().split('.')[0]
const snake = `${split.join('_')}${event}`
return camel(snake)
}
exportFunction()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment