v1.1.0/setup emulators

This commit is contained in:
2021-04-18 20:52:40 -04:00
parent 7b3d288967
commit 3055bf4521
4 changed files with 47 additions and 6 deletions
+3
View File
@@ -23,3 +23,6 @@ npm-debug.log*
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
*.cache *.cache
*.log
functions/lib/
functions/src/backup.json
+16 -1
View File
@@ -49,6 +49,21 @@
"predeploy": [ "predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint", "npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build" "npm --prefix \"$RESOURCE_DIR\" run build"
] ],
"source": "functions"
},
"emulators": {
"functions": {
"port": 5001
},
"firestore": {
"port": 8080
},
"hosting": {
"port": 5000
},
"ui": {
"enabled": true
}
} }
} }
+2 -1
View File
@@ -3,7 +3,8 @@
"scripts": { "scripts": {
"lint": "eslint --ext .js,.ts .", "lint": "eslint --ext .js,.ts .",
"build": "tsc", "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", "shell": "npm run build && firebase functions:shell",
"start": "npm run shell", "start": "npm run shell",
"deploy": "firebase deploy --only functions", "deploy": "firebase deploy --only functions",
+22
View File
@@ -37,6 +37,28 @@ const serializeGaId = (_gaid: string): string => {
return ""; 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, Record<string,
boolean | Record<string, unknown> | string>> =
backup.results;
const BackupStats : Record<string,
Record<string, unknown> |
Record<string, number> |
Record<string, Record<string, number> |
Record<string, Record<string, Record<string, number>>>>> =
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( export const saveResult = functions.https.onCall(
async (data: SaveResultRequestData, context) => { async (data: SaveResultRequestData, context) => {
if (!!data && !!context) { if (!!data && !!context) {