Last active
September 1, 2018 16:44
-
-
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
This file contains hidden or 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 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