Skip to content

Instantly share code, notes, and snippets.

@georgesboris
Last active June 14, 2017 19:37
Show Gist options
  • Save georgesboris/79d851a030423fac3a3a8a5b375a2616 to your computer and use it in GitHub Desktop.
Save georgesboris/79d851a030423fac3a3a8a5b375a2616 to your computer and use it in GitHub Desktop.
self importing firebase-functions
/**
* Require all functions files.
* /src/{function}/{function}.js
*
* functions must export
* {
* key: string the name of the function,
* watcher: fn the firebase-function watcher function
* }
*
*/
let functions = [];
require('fs').readdirSync(__dirname + '/src/').forEach(function(file) {
if (!file.startsWith('.')) {
require(`./src/${file}/${file}`)(functions);
}
});
/**
* Export functions
*/
functions.forEach((fn) => {
exports[fn.key] = fn.watcher;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment