unable to split Firebase functions in multiple files

前端 未结 4 1876
名媛妹妹
名媛妹妹 2021-02-05 10:17

I\'m working with firebase functions and arrived to hundreds of functions, and now it is very hard to manage it in single index.js file as shown in their lots of ex

4条回答
  •  迷失自我
    2021-02-05 11:05

    //index.js
    const glob = require('glob')
    const files = glob.sync('./**/*.functions.js', { cwd: __dirname, 
    ignore: './node_modules/**' })
    
    files.forEach(file => {
    const functionModule = require(file)
    const functionNames = Object.keys(functionModule)
    
    functionNames.forEach(functionName => {
        if (!process.env.FUNCTION_NAME || process.env.FUNCTION_NAME === 
        functionName) {
             exports[functionName] = functionModule[functionName]
         }
      })
     })
    

    Folders like so.. will work

     //Example Home.functions.js :
     exports.Home = functions.https..
    

提交回复
热议问题