Skip to content

Commit 9bf73ff

Browse files
committed
add working structure
1 parent 6fd7ed3 commit 9bf73ff

17 files changed

+3497
-130
lines changed

README.md

+42-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,44 @@
11
# firebase-cloud-functions-typescript
22

3-
Firebase Cloud Functions with TypeScript.
3+
## Firebase Cloud Functions (TypeScript)
4+
5+
### Quick start
6+
7+
> Requirement: Node.js >= v.8
8+
9+
```bash
10+
# To quickly deploy (or update existing) Firebase Functions to GCP:
11+
$ cd firebase-functions
12+
$ npm install
13+
# set your default project name in the firebase.json file, and then run:
14+
$ npm run deploy
15+
16+
# In order to deploy single functions, you will have to install `firebase-tools` locally:
17+
$ npm install -g firebase-tools
18+
$ firebase deploy --only functions:{functionName}
19+
# The function names can be found in firebase-functions/src/index.ts, e.g. "firebase_firebaseFunction1"
20+
```
21+
22+
The "deploy" command will run tslint, transpile into JavaScript (ES2017) under the "lib" directory, perform unit tests and deploy the transpiled code to Google Cloud Platform.
23+
24+
**Important note: All functions using the "firebase-admin" SDK should initialize the SDK in the following manner:**
25+
26+
```javascript
27+
import * as functions from 'firebase-functions';
28+
import * as admin from "firebase-admin";
29+
try {admin.initializeApp(functions.config().firebase);} catch(e) {}
30+
```
31+
32+
Otherwise, the SDK might be initialized more than once - which will lead to an error on deployment.
33+
34+
### Unit Testing
35+
36+
The Firebase Cloud Functions use unit tests using Mocha and Chai for assertions.
37+
38+
### Creating new functions
39+
40+
Create a `.ts` file under `firebase-functions/src/`.
41+
42+
After that export the function in the `index.ts` file.
43+
44+
If you want to create any unit tests, do so in the `test` folder.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)