Created
December 29, 2020 19:58
-
-
Save tettoffensive/583db1c98633a7220b80315422c83ffd to your computer and use it in GitHub Desktop.
Import all Firebase Functions.
This file contains 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
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