Skip to content

Instantly share code, notes, and snippets.

@tettoffensive
Created December 29, 2020 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tettoffensive/583db1c98633a7220b80315422c83ffd to your computer and use it in GitHub Desktop.
Save tettoffensive/583db1c98633a7220b80315422c83ffd to your computer and use it in GitHub Desktop.
Import all Firebase Functions.
import { sync } from 'glob';
import { camelCase, last } from 'lodash';
const files = sync('./**/*.function.[tj]s', { cwd: __dirname, ignore: './node_modules/**' });
for (let f = 0, fl = files.length; f < fl; f += 1) {
const file = files[f];
const functionName = camelCase(last(file.slice(0, -12).split('/'))); // Strip off '.function.js'
if (!process.env.FUNCTION_NAME || process.env.FUNCTION_NAME === functionName) {
// eslint-disable-next-line import/no-dynamic-require, global-require
exports[functionName] = require(file);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment