From 3055bf4521267da0e04f85f55391334f9dd858a6 Mon Sep 17 00:00:00 2001 From: Ayushya Amitabh Date: Sun, 18 Apr 2021 20:52:40 -0400 Subject: [PATCH] v1.1.0/setup emulators --- .gitignore | 3 +++ firebase.json | 25 ++++++++++++++++++++----- functions/package.json | 3 ++- functions/src/index.ts | 22 ++++++++++++++++++++++ 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 9f8216a..e243278 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ npm-debug.log* yarn-debug.log* yarn-error.log* *.cache +*.log +functions/lib/ +functions/src/backup.json diff --git a/firebase.json b/firebase.json index ed181fb..4128b13 100644 --- a/firebase.json +++ b/firebase.json @@ -9,11 +9,11 @@ "rewrites": [ { "source": "/copyright", - "destination" : "/copyright.html" + "destination": "/copyright.html" }, { "source": "/privacy", - "destination" : "/privacy.html" + "destination": "/privacy.html" }, { "source": "/jj", @@ -24,7 +24,7 @@ "destination": "/index.html" }, { - "source": "/md", + "source": "/md", "destination": "/index.html" }, { @@ -36,7 +36,7 @@ "destination": "/index.html" }, { - "source": "/md/**", + "source": "/md/**", "destination": "/index.html" }, { @@ -49,6 +49,21 @@ "predeploy": [ "npm --prefix \"$RESOURCE_DIR\" run lint", "npm --prefix \"$RESOURCE_DIR\" run build" - ] + ], + "source": "functions" + }, + "emulators": { + "functions": { + "port": 5001 + }, + "firestore": { + "port": 8080 + }, + "hosting": { + "port": 5000 + }, + "ui": { + "enabled": true + } } } diff --git a/functions/package.json b/functions/package.json index 132ebac..e6e9276 100644 --- a/functions/package.json +++ b/functions/package.json @@ -3,7 +3,8 @@ "scripts": { "lint": "eslint --ext .js,.ts .", "build": "tsc", - "serve": "npm run build && firebase emulators:start --only functions", + "serve": "npm run devenv && npm run build && $env:NODE_ENV=DEV && firebase emulators:start", + "devenv": "SET NODE_ENV=dev", "shell": "npm run build && firebase functions:shell", "start": "npm run shell", "deploy": "firebase deploy --only functions", diff --git a/functions/src/index.ts b/functions/src/index.ts index d96f6b5..3ea201f 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -37,6 +37,28 @@ const serializeGaId = (_gaid: string): string => { return ""; }; +if (process.env.NODE_ENV && process.env.NODE_ENV === "dev") { + // eslint-disable-next-line @typescript-eslint/no-var-requires + const backup = require("./backup.json"); + const BackupResults : Record | string>> = + backup.results; + + const BackupStats : Record | + Record | + Record | + Record>>>> = + backup.stats; + + Object.keys(BackupResults).forEach((key : string) => { + admin.firestore().collection("results").doc(key).set(BackupResults[key]); + }); + Object.keys(BackupStats).forEach((key : string) => { + admin.firestore().collection("stats").doc(key).set(BackupStats[key]); + }); +} + export const saveResult = functions.https.onCall( async (data: SaveResultRequestData, context) => { if (!!data && !!context) {