Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jacob-ian/firebase-functions-exporter
A helper tool to automatically import and export Firebase Functions from a directory.
https://github.com/jacob-ian/firebase-functions-exporter
firebase firebase-functions javascript typescript
Last synced: 13 days ago
JSON representation
A helper tool to automatically import and export Firebase Functions from a directory.
- Host: GitHub
- URL: https://github.com/jacob-ian/firebase-functions-exporter
- Owner: jacob-ian
- License: mit
- Created: 2022-04-23T09:55:57.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-05-26T11:57:45.000Z (over 2 years ago)
- Last Synced: 2024-10-10T23:12:17.198Z (26 days ago)
- Topics: firebase, firebase-functions, javascript, typescript
- Language: TypeScript
- Homepage:
- Size: 165 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Firebase Functions Exporter
A utility that quickly exports all TypeScript/JavaScript Firebase Functions from all of a directory's subdirectories.## Usage
1. Install the package in your Firebase Functions directory (usually `/functions`):
1. With Yarn: `yarn add firebase-functions-exporter`
2. With NPM: `npm i --save firebase-functions-exporter`
2. Write your Firebase Functions in their own files, following the pattern `[NAME].function.ts` or `[NAME].function.js`, grouped in directories of your choosing. For example:
1. TypeScript (with functions grouped by type):
```
functions
src
index.ts
callable
updateUser.function.ts
createUser.function.ts
restful
posts.function.ts
event
onUserCreate.function.ts
```
`functions/src/event/onUserCreate.function.ts`:
```ts
import * as functions from 'firebase-functions';export const onUserCreate = functions.auth.user().onCreate((user, context) => {
functions.logger().log(`User created: ${JSON.stringify(user)}`);
});
```
1. JavaScript (with functions grouped by category):
```
functions
index.js
users
createUser.function.js
updateUser.function.js
onUserCreate.function.js
posts
onPostUpdate.function.js
```
`functions/posts/onPostUpdate.function.js`
```js
const functions = require('firebase-functions');exports.onPostUpdate = functions.firestore.document('/post/{postId}')
.onUpdate((snap, context) => {
functions.logger.log(`Post Updated: ${JSON.stringify(snap)}`);
})
```
3. Define `exportFunctions` as the export in the functions index file:
1. TypeScript:
`functions/src/index.ts`:
```ts
import { exportFunctions } from 'firebase-functions-exporter';module.exports = exportFunctions();
```
1. JavaScript: `functions/index.js`:
```js
const { exportFunctions } = require('firebase-functions-exporter');module.exports = exportFunctions()
```
4. Deploy to Firebase Functions:
`firebase deploy --only functions`.## Notes
- If using default exports, the function will take the name of the file, i.e. the name of a default exported function in the file `onUserCreate.function.ts` will be `onUserCreate`.
- Deploying to Firebase Functions will fail if two or more functions have the same name.## Licence
MIT