Skip to content

Commit c6030bd

Browse files
committed
Server Firestore from emulator
1 parent e47f989 commit c6030bd

File tree

13 files changed

+99
-40
lines changed

13 files changed

+99
-40
lines changed

.github/workflows/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
script-name: [lint, test, build, types]
12+
script-name: [lint, test, build, types, seed]
1313

1414
steps:
1515
- name: Checkout the repo

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
dist/
33
package-lock.json
4+
data/seed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"kind":"identitytoolkit#DownloadAccountResponse","users":[]}

data/seed/auth_export/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"signIn":{"allowDuplicateEmails":false},"usageMode":"DEFAULT"}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": "9.23.0",
3+
"firestore": {
4+
"version": "1.13.1",
5+
"path": "firestore_export",
6+
"metadata_file": "firestore_export/firestore_export.overall_export_metadata"
7+
},
8+
"auth": {
9+
"version": "9.23.0",
10+
"path": "auth_export"
11+
},
12+
"storage": {
13+
"version": "9.23.0",
14+
"path": "storage_export"
15+
}
16+
}
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"buckets": [
3+
{
4+
"id": "default-bucket"
5+
}
6+
]
7+
}

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
"build": "npm run clean && NODE_ENV=production rollup --config rollup.config.js",
1212
"clean": "rimraf dist",
1313
"deploy": "npm run build && NODE_ENV=production firebase deploy",
14+
"emulators:export": "firebase emulators:export ./data/seed",
15+
"emulators:import": "FIRESTORE_EMULATOR_HOST=\"localhost:8080\" ts-node-script ./scripts/import",
1416
"firestore:copy": "ts-node-script ./scripts/firestore-copy",
15-
"firestore:init": "ts-node-script ./scripts/firestore-init",
17+
"firestore:init": "ts-node-script ./scripts/import",
1618
"fix": "concurrently npm:fix:*",
1719
"fix:eslint": "eslint . --ext .ts --ext .js --fix",
1820
"fix:prettier": "prettier . --write",
@@ -23,9 +25,10 @@
2325
"lint:prettier": "prettier --check .",
2426
"lint:stylelint": "stylelint \"src/components/**/*.ts\" \"src/styles/**/*.ts\"",
2527
"postinstall": "npm run install:functions",
28+
"seed": "firebase emulators:exec \"./scripts/validate-seed.sh\"",
2629
"serve": "NODE_ENV=production concurrently --kill-others npm:start:*",
2730
"start": "NODE_ENV=development concurrently --kill-others npm:start:*",
28-
"start:emulators": "firebase emulators:start",
31+
"start:emulators": "firebase emulators:start --import data/seed",
2932
"start:functions": "npm --prefix functions start",
3033
"start:rollup": "rollup --config rollup.config.js --watch",
3134
"test": "jest",

scripts/firebase-config.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ import { cert, initializeApp, ServiceAccount } from 'firebase-admin/app';
66
import { getFirestore } from 'firebase-admin/firestore';
77
import serviceAccount from '../serviceAccount.json';
88

9-
const credential = cert(serviceAccount as ServiceAccount);
10-
initializeApp({ credential });
9+
const { FIRESTORE_EMULATOR_HOST } = process.env;
10+
11+
if (FIRESTORE_EMULATOR_HOST) {
12+
initializeApp({ projectId: 'demo-hoverboard' });
13+
} else {
14+
const credential = cert(serviceAccount as ServiceAccount);
15+
initializeApp({ credential });
16+
}
17+
1118
const firestore = getFirestore();
1219

1320
export { firestore };

scripts/firestore-init/index.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)