@sca-digital/cloud-function-generator
v0.1.9
Published
This project aims to consolate our cloud functions by setting up templates for using Firebase functions. Google Cloud functions to come at a later date.
Downloads
22
Readme
Cloud function template generator
This project aims to consolate our cloud functions by setting up templates for using Firebase functions. Google Cloud functions to come at a later date.
Hopefully all the defaults are sane and uses the following:
- Eslint / Prettier (simple defaults)
- Jest for testing
- Basic Gitlab pipline
To use
npx @sca-digital/cloud-function-generator
This will start a program that asks questions about how you want to use Firebase.
File Structure
Once run, it will generate a project with the following structure:
├── .eslintrc /* Linting */
├── .gitignore /* Ignores */
├── .gitlab-ci.yml /* Gitlab pipeline */
├── .prettierrc.js /* Code formatting */
├── README.md
├── firebase.json /* Firebase config */
└── functions
├── .gitignore
├── .prettierrc
├── index.js /* Central import */
├── package.json
└── testProject
└── index.js /* Main package */
The reason for the nesting of the central import is so that all functions are namespaced with the project name.
For example, a project name testProject
, with a function inside functions/testProject/index.js
called myFunction
, will generate testProject-myFunction
in Firebase/GCP.
This also means that Gitlab configs can stay vert simple, by using only one function export in it's deploy.
Testing
This project uses Jest as a test runner, with all tests talking to emulators provided by Firebase Tools or Functions Framework for GCP.
Ideally, use these rather than mocking, since it gives better confidence in how our functions are used and doesn't rely on real resources.
Template updates
If you'd like to see a change to a template, create a branch then raise a merge request and assign to @Stenmark