From dbd4d851a6eff9188ab470d709e90b5f31b06e45 Mon Sep 17 00:00:00 2001 From: Jacob Cable Date: Fri, 19 Apr 2024 14:04:23 +0100 Subject: [PATCH] test(*): test change --- .github/workflows/conditional-test.yml | 73 +++++-- delete-user-data/functions/package-lock.json | 218 +++++++++++++++++++ delete-user-data/functions/package.json | 12 +- delete-user-data/functions/src/index.ts | 1 + firestore-send-email/functions/package.json | 6 +- firestore-send-email/functions/src/index.ts | 1 - scripts/changeFirebaseJson.cjs | 66 ++++++ 7 files changed, 345 insertions(+), 32 deletions(-) create mode 100644 scripts/changeFirebaseJson.cjs diff --git a/.github/workflows/conditional-test.yml b/.github/workflows/conditional-test.yml index 03f006ec05..834233c51f 100644 --- a/.github/workflows/conditional-test.yml +++ b/.github/workflows/conditional-test.yml @@ -12,51 +12,78 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 + with: + fetch-depth: 0 # Fetch all history for all branches and tags + ref: ${{ github.head_ref }} # Ensure PR's head is checked out - name: Get changed directories id: set_changed run: | echo "::group::Determining Changed Directories" - # List specific directories you want to check DIRECTORIES="auth-mailchimp-sync delete-user-data firestore-bigquery-export firestore-counter firestore-send-email firestore-shorten-urls-bitly firestore-translate-text rtdb-limit-child-nodes storage-resize-images" - # Initialize an empty string to hold the paths of changed directories - CHANGED_EXTENSIONS="" + # Set commit SHAs for comparison + BASE_SHA=${{ github.event.pull_request.base.sha }} + HEAD_SHA=${{ github.event.pull_request.head.sha }} + + # Initialize an empty JSON array + CHANGED_EXTENSIONS_JSON="[" + + if ! git diff --name-only $BASE_SHA $HEAD_SHA > /dev/null 2>&1; then + echo "Error detecting changes using PR base and head SHAs, falling back to default branch comparison." + git fetch --no-tags --depth=1 origin +refs/heads/next:refs/remotes/origin/next + BASE_SHA=$(git rev-parse origin/next) + fi - # Loop through each directory and check if there have been any changes + first_entry=true for dir in $DIRECTORIES; do - if git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep -q "^extensions/$dir/"; then - CHANGED_EXTENSIONS+="$dir " + if git diff --name-only $BASE_SHA $HEAD_SHA | grep -q "^$dir/"; then + if [ "$first_entry" = true ]; then + first_entry=false + else + CHANGED_EXTENSIONS_JSON+=", " + fi + CHANGED_EXTENSIONS_JSON+="\"$dir\"" fi done - # Trim any trailing whitespace and print the output - CHANGED_EXTENSIONS=$(echo $CHANGED_EXTENSIONS | xargs) - echo "Changed extensions: $CHANGED_EXTENSIONS" + CHANGED_EXTENSIONS_JSON+="]" + + # Output the JSON array to the workflow + echo "changed_extensions=$CHANGED_EXTENSIONS_JSON" >> $GITHUB_OUTPUT + echo "Changed extensions: $CHANGED_EXTENSIONS_JSON" echo "::endgroup::" - echo "::set-output name=changed_extensions::$CHANGED_EXTENSIONS" test_extensions: needs: check_changes runs-on: ubuntu-latest strategy: + fail-fast: false matrix: extension: ${{ fromJson(needs.check_changes.outputs.changed_extensions) }} - defaults: - run: - working-directory: extensions/${{ matrix.extension }}/functions steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Setup node - uses: actions/setup-node@v3 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: node-version: "18" cache: "npm" cache-dependency-path: "**/package-lock.json" - - name: Install dependencies - run: npm install - - name: Build - run: npm run build - - name: Run tests - run: npm test + - name: Install Firebase CLI + uses: nick-invision/retry@v1 + with: + timeout_minutes: 10 + retry_wait_seconds: 60 + max_attempts: 3 + command: npm i -g firebase-tools@11 + + - name: Setup e2e secrets + run: | + echo SMTP_PASSWORD=${{ secrets.SENDGRID_API_KEY }} >> _emulator/extensions/firestore-send-email-sendgrid.secret.local + + - run: cd ${{ matrix.extension }}/functions && npm install + - run: cd ${{ matrix.extension }}/functions && npm run build + - run: node scripts/changeFirebaseJson.cjs ${{ matrix.extension }} + - name: Start Firebase Emulator + run: cd _emulator && firebase emulators:start & + - run: + cd ${{ matrix.extension }}/functions && npm run testIfEmulatorRunning diff --git a/delete-user-data/functions/package-lock.json b/delete-user-data/functions/package-lock.json index 822199454a..ccd18b444f 100644 --- a/delete-user-data/functions/package-lock.json +++ b/delete-user-data/functions/package-lock.json @@ -27,6 +27,7 @@ "concurrency": "^0.1.4", "dotenv": "^16.0.2", "firebase-functions-test": "^3.2.0", + "wait-on": "^7.2.0", "wait-port": "^0.2.9" }, "engines": { @@ -836,6 +837,21 @@ "node": ">=6" } }, + "node_modules/@hapi/hoek": { + "version": "9.3.0", + "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-9.3.0.tgz", + "integrity": "sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ==", + "dev": true + }, + "node_modules/@hapi/topo": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-5.1.0.tgz", + "integrity": "sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg==", + "dev": true, + "dependencies": { + "@hapi/hoek": "^9.0.0" + } + }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -1253,6 +1269,27 @@ "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz", "integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==" }, + "node_modules/@sideway/address": { + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.5.tgz", + "integrity": "sha512-IqO/DUQHUkPeixNQ8n0JA6102hT9CmaljNTPmQ1u8MEhBo/R4Q8eKLN/vGZxuebwOroDB4cbpjheD4+/sKFK4Q==", + "dev": true, + "dependencies": { + "@hapi/hoek": "^9.0.0" + } + }, + "node_modules/@sideway/formula": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@sideway/formula/-/formula-3.0.1.tgz", + "integrity": "sha512-/poHZJJVjx3L+zVD6g9KgHfYnb443oi7wLu/XKojDviHy6HOEOA6z1Trk5aR1dGcmPenJEgb2sK2I80LeS3MIg==", + "dev": true + }, + "node_modules/@sideway/pinpoint": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@sideway/pinpoint/-/pinpoint-2.0.0.tgz", + "integrity": "sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ==", + "dev": true + }, "node_modules/@sinclair/typebox": { "version": "0.27.8", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", @@ -1681,6 +1718,31 @@ "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, + "node_modules/axios": { + "version": "1.6.8", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", + "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", + "dev": true, + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/axios/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/babel-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.7.0.tgz", @@ -2848,6 +2910,26 @@ "jest": ">=28.0.0" } }, + "node_modules/follow-redirects": { + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/form-data": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", @@ -4104,6 +4186,19 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/joi": { + "version": "17.13.0", + "resolved": "https://registry.npmjs.org/joi/-/joi-17.13.0.tgz", + "integrity": "sha512-9qcrTyoBmFZRNHeVP4edKqIUEgFzq7MHvTNSDuHSqkpOPtiBkgNgcmTSqmiw1kw9tdKaiddvIDv/eCJDxmqWCA==", + "dev": true, + "dependencies": { + "@hapi/hoek": "^9.3.0", + "@hapi/topo": "^5.1.0", + "@sideway/address": "^4.1.5", + "@sideway/formula": "^3.0.1", + "@sideway/pinpoint": "^2.0.0" + } + }, "node_modules/jose": { "version": "4.15.5", "resolved": "https://registry.npmjs.org/jose/-/jose-4.15.5.tgz", @@ -4995,6 +5090,12 @@ "node": ">= 0.10" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "dev": true + }, "node_modules/pseudomap": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", @@ -5916,6 +6017,25 @@ "node": ">= 0.8" } }, + "node_modules/wait-on": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/wait-on/-/wait-on-7.2.0.tgz", + "integrity": "sha512-wCQcHkRazgjG5XoAq9jbTMLpNIjoSlZslrJ2+N9MxDsGEv1HnFoVjOCexL0ESva7Y9cu350j+DWADdk54s4AFQ==", + "dev": true, + "dependencies": { + "axios": "^1.6.1", + "joi": "^17.11.0", + "lodash": "^4.17.21", + "minimist": "^1.2.8", + "rxjs": "^7.8.1" + }, + "bin": { + "wait-on": "bin/wait-on" + }, + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/wait-port": { "version": "0.2.14", "resolved": "https://registry.npmjs.org/wait-port/-/wait-port-0.2.14.tgz", @@ -6809,6 +6929,21 @@ "yargs": "^17.7.2" } }, + "@hapi/hoek": { + "version": "9.3.0", + "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-9.3.0.tgz", + "integrity": "sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ==", + "dev": true + }, + "@hapi/topo": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-5.1.0.tgz", + "integrity": "sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg==", + "dev": true, + "requires": { + "@hapi/hoek": "^9.0.0" + } + }, "@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -7142,6 +7277,27 @@ "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz", "integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==" }, + "@sideway/address": { + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.5.tgz", + "integrity": "sha512-IqO/DUQHUkPeixNQ8n0JA6102hT9CmaljNTPmQ1u8MEhBo/R4Q8eKLN/vGZxuebwOroDB4cbpjheD4+/sKFK4Q==", + "dev": true, + "requires": { + "@hapi/hoek": "^9.0.0" + } + }, + "@sideway/formula": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@sideway/formula/-/formula-3.0.1.tgz", + "integrity": "sha512-/poHZJJVjx3L+zVD6g9KgHfYnb443oi7wLu/XKojDviHy6HOEOA6z1Trk5aR1dGcmPenJEgb2sK2I80LeS3MIg==", + "dev": true + }, + "@sideway/pinpoint": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@sideway/pinpoint/-/pinpoint-2.0.0.tgz", + "integrity": "sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ==", + "dev": true + }, "@sinclair/typebox": { "version": "0.27.8", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", @@ -7532,6 +7688,30 @@ "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, + "axios": { + "version": "1.6.8", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", + "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", + "dev": true, + "requires": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + }, + "dependencies": { + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + } + } + }, "babel-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.7.0.tgz", @@ -8363,6 +8543,12 @@ "ts-deepmerge": "^2.0.1" } }, + "follow-redirects": { + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", + "dev": true + }, "form-data": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", @@ -9283,6 +9469,19 @@ "supports-color": "^8.0.0" } }, + "joi": { + "version": "17.13.0", + "resolved": "https://registry.npmjs.org/joi/-/joi-17.13.0.tgz", + "integrity": "sha512-9qcrTyoBmFZRNHeVP4edKqIUEgFzq7MHvTNSDuHSqkpOPtiBkgNgcmTSqmiw1kw9tdKaiddvIDv/eCJDxmqWCA==", + "dev": true, + "requires": { + "@hapi/hoek": "^9.3.0", + "@hapi/topo": "^5.1.0", + "@sideway/address": "^4.1.5", + "@sideway/formula": "^3.0.1", + "@sideway/pinpoint": "^2.0.0" + } + }, "jose": { "version": "4.15.5", "resolved": "https://registry.npmjs.org/jose/-/jose-4.15.5.tgz", @@ -9962,6 +10161,12 @@ "ipaddr.js": "1.9.1" } }, + "proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "dev": true + }, "pseudomap": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", @@ -10586,6 +10791,19 @@ "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==" }, + "wait-on": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/wait-on/-/wait-on-7.2.0.tgz", + "integrity": "sha512-wCQcHkRazgjG5XoAq9jbTMLpNIjoSlZslrJ2+N9MxDsGEv1HnFoVjOCexL0ESva7Y9cu350j+DWADdk54s4AFQ==", + "dev": true, + "requires": { + "axios": "^1.6.1", + "joi": "^17.11.0", + "lodash": "^4.17.21", + "minimist": "^1.2.8", + "rxjs": "^7.8.1" + } + }, "wait-port": { "version": "0.2.14", "resolved": "https://registry.npmjs.org/wait-port/-/wait-port-0.2.14.tgz", diff --git a/delete-user-data/functions/package.json b/delete-user-data/functions/package.json index d535526026..715819476b 100644 --- a/delete-user-data/functions/package.json +++ b/delete-user-data/functions/package.json @@ -13,24 +13,25 @@ "test:local": "cd ../../_emulator && firebase emulators:exec \"CI_TEST=true jest --detectOpenHandles --verbose --forceExit --testMatch **/delete-user-data/**/*.test.ts\"", "test:watch": "concurrently \"npm run local:emulator\" \"jest --watch\"", "generate-readme": "firebase ext:info .. --markdown > ../README.md", - "test:emulator-running": "jest" + "test:emulator-running": "jest", + "testIfEmulatorRunning": "wait-on tcp:4001 && jest" }, "author": "Lauren Long ", "license": "Apache-2.0", "dependencies": { "@google-cloud/pubsub": "^4.3.3", "@types/express-serve-static-core": "4.17.24", + "@types/jest": "29.5.0", "@types/node": "^16.18.34", "concurrently": "^7.2.1", "firebase-admin": "^12.1.0", "firebase-functions": "^4.9.0", + "jest": "29.5.0", "lodash.chunk": "^4.2.0", "node-fetch": "^2.6.2", "rimraf": "^2.6.3", - "typescript": "^4.9.4", - "@types/jest": "29.5.0", - "jest": "29.5.0", - "ts-jest": "29.1.2" + "ts-jest": "29.1.2", + "typescript": "^4.9.4" }, "engines": { "node": "18" @@ -42,6 +43,7 @@ "concurrency": "^0.1.4", "dotenv": "^16.0.2", "firebase-functions-test": "^3.2.0", + "wait-on": "^7.2.0", "wait-port": "^0.2.9" } } diff --git a/delete-user-data/functions/src/index.ts b/delete-user-data/functions/src/index.ts index d4afd16a6f..a7a524ea5a 100644 --- a/delete-user-data/functions/src/index.ts +++ b/delete-user-data/functions/src/index.ts @@ -33,6 +33,7 @@ const databaseURL = getDatabaseUrl( config.selectedDatabaseInstance, config.selectedDatabaseLocation ); +console.log(""); // Initialize the Firebase Admin SDK admin.initializeApp({ diff --git a/firestore-send-email/functions/package.json b/firestore-send-email/functions/package.json index a0abe55c79..9d40b840c7 100644 --- a/firestore-send-email/functions/package.json +++ b/firestore-send-email/functions/package.json @@ -8,10 +8,10 @@ "build:watch": "npm run clean && tsc --watch", "clean": "rimraf lib", "compile": "tsc", - "local:emulator": "cd ../../_emulator && firebase emulators:start -P demo-test", - "test": "cd ../../_emulator && firebase emulators:exec --only extensions jest -P demo-test", + "local:emulator": "cd ../../_emulator && ./emulator_wrapper.sh", + "test": "cd ../../_emulator && firebase emulators:exec jest -P demo-test", "testIfEmulatorRunning": "wait-on tcp:4001 && jest", - "test:local": "concurrently --kill-others \"npm run local:emulator\" \"npm run testIfEmulatorRunning\"", + "test:local": "concurrently --kill-others \"npm run local:emulator || exit 0\" \"npm run testIfEmulatorRunning\"", "test:watch": "concurrently \"npm run local:emulator\" \"jest --watch\"", "generate-readme": "firebase ext:info .. --markdown > ../README.md" }, diff --git a/firestore-send-email/functions/src/index.ts b/firestore-send-email/functions/src/index.ts index ce8eb3ed0f..10791ced41 100644 --- a/firestore-send-email/functions/src/index.ts +++ b/firestore-send-email/functions/src/index.ts @@ -27,7 +27,6 @@ import { parseTlsOptions, setSmtpCredentials } from "./helpers"; import * as events from "./events"; logs.init(); - let db: admin.firestore.Firestore; let transport: nodemailer.Transporter; let templates: Templates; diff --git a/scripts/changeFirebaseJson.cjs b/scripts/changeFirebaseJson.cjs new file mode 100644 index 0000000000..a0e308b9c5 --- /dev/null +++ b/scripts/changeFirebaseJson.cjs @@ -0,0 +1,66 @@ +const fs = require('fs'); +const path = require('path'); + +// get extensionName from args +// e.g node scripts/changeFirebaseJson.cjs firestore-send-email +const extensionName = process.argv[2]; + + +const cwd = process.cwd(); + +const filePath = path.join(cwd,'_emulator','firebase.json'); // Adjust the path as necessary + +fs.readFile(filePath, { encoding: 'utf8' }, (err, data) => { + if (err) { + console.error('Error reading file:', err); + return; + } + + // Parse the JSON data + let config = JSON.parse(data); + + // "firestore-send-email": "../firestore-send-email", + // "delete-user-data": "../delete-user-data", + // "storage-resize-images": "../storage-resize-images", + // "firestore-counter": "../firestore-counter", + // "firestore-bigquery-export": "../firestore-bigquery-export", + // "firestore-send-email-sendgrid": "../firestore-send-email" + + +const extensionsFields = { + "firestore-send-email": { + "firestore-send-email": "../firestore-send-email", + "firestore-send-email-sendgrid": "../firestore-send-email" + }, + "delete-user-data": { + "delete-user-data": "../delete-user-data" + }, + "storage-resize-images": { + "storage-resize-images": "../storage-resize-images" + }, + "firestore-counter": { + "firestore-counter": "../firestore-counter" + }, + "firestore-bigquery-export": { + "firestore-bigquery-export": "../firestore-bigquery-export" + }, +} + + const extensionDeclarations = extensionsFields[extensionName]; + + + // Update the extensions field + config.extensions = extensionDeclarations; + + // Convert the modified config back to a JSON string + const updatedJson = JSON.stringify(config, null, 2); // Including null and 2 for pretty-printing + + // Write the JSON string back to the file + fs.writeFile(filePath, updatedJson, (err) => { + if (err) { + console.error('Error writing file:', err); + } else { + console.log('firebase.json has been updated successfully!'); + } + }); +});