This project contains Firebase Cloud Functions to support a real-time cricket scoring web application using Firestore. It processes ball-by-ball data and updates match state documents such as live scores, batting and bowling summaries, and innings info.
cricket-score-functions/
βββ firebase.json # Firebase configuration (emulators, deploy targets, etc.)
βββ .firebaserc # Project alias and default Firebase project
βββ functions/
βββ package.json # NPM dependencies and scripts
βββ tsconfig.json # TypeScript compiler settings
βββ src/
β βββ index.ts # Main entry for cloud functions
βββ lib/ # Compiled JS output (auto-generated)
- Node.js (v18+ recommended)
- Firebase CLI
- Yarn or
npm
git clone https://github.com/your-username/cricket-score-functions.git
cd cricket-score-functions/functions
yarn install # or npm installRun Firebase emulators locally:
firebase emulators:startCompile TypeScript in watch mode:
yarn run build:watch # or npm run build:watchYou can edit
src/index.tsβ compiled code appears inlib/.
To deploy functions to your Firebase project:
firebase deploy --only functionsYour Cloud Functions listen to writes/updates/deletes on:
/feed/{id}β each ball in the match- On create: processes the ball and updates game state
- On update/delete: recalculates totals and cleans up affected documents
And update:
/main/liveβ live match summary/battingβ current batting lineup with stats/bowling/{id}β current bowling stats/inningβ track innings progression and scores
| Script | Description |
|---|---|
build |
Compiles TypeScript β JS |
build:watch |
Watch mode for development |
deploy |
Deploys functions to Firebase |
emulators |
Starts local emulator suite |
You can add these to package.json:
"scripts": {
"build": "tsc",
"build:watch": "tsc --watch",
"deploy": "firebase deploy --only functions",
"emulators": "firebase emulators:start"
}