From 0f344d985c01fa794142bd22358d132dc59240af Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Fri, 2 Apr 2021 22:24:59 -0400 Subject: [PATCH 1/6] Added the dotenv package. --- package.json | 3 +++ yarn.lock | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/package.json b/package.json index 954ea048..fefc750d 100644 --- a/package.json +++ b/package.json @@ -40,5 +40,8 @@ "uuid": "^8.3.2", "yup": "^0.32.8", "zustand": "^3.3.1" + }, + "devDependencies": { + "dotenv": "^8.2.0" } } diff --git a/yarn.lock b/yarn.lock index ab03b2e3..f4d34f15 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2669,6 +2669,11 @@ dot-prop@^5.2.0: dependencies: is-obj "^2.0.0" +dotenv@^8.2.0: + version "8.2.0" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a" + integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw== + duplexify@^3.4.2, duplexify@^3.6.0: version "3.7.1" resolved "https://registry.yarnpkg.com/duplexify/-/duplexify-3.7.1.tgz#2a4df5317f6ccfd91f86d6fd25d8d8a103b88309" From f48e29516c2a618f247d924835470c323f84b139 Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Fri, 2 Apr 2021 22:50:36 -0400 Subject: [PATCH 2/6] Added the FIRESTORE_EMULATOR_HOST environment variable to the .env.local template. --- .env.local.template | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.local.template b/.env.local.template index d9ea77f1..d9532f54 100644 --- a/.env.local.template +++ b/.env.local.template @@ -6,3 +6,4 @@ STORAGE_BUCKET = "" MESSAGING_SENDER_ID = "" APP_ID = "" BASE_URL = "http://localhost:3000" +FIRESTORE_EMULATOR_HOST = "localhost:8080" \ No newline at end of file From a60b3cecee74361b15b248449ef209585c916cbf Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Fri, 2 Apr 2021 22:51:06 -0400 Subject: [PATCH 3/6] Added the yargs package to the project. --- package.json | 3 ++- yarn.lock | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index fefc750d..c56d48e8 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "zustand": "^3.3.1" }, "devDependencies": { - "dotenv": "^8.2.0" + "dotenv": "^8.2.0", + "yargs": "^16.2.0" } } diff --git a/yarn.lock b/yarn.lock index f4d34f15..1b9f2427 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1983,6 +1983,15 @@ cli-truncate@^0.2.1: slice-ansi "0.0.4" string-width "^1.0.1" +cliui@^7.0.2: + version "7.0.4" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-7.0.4.tgz#a0265ee655476fc807aea9df3df8df7783808b4f" + integrity sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ== + dependencies: + string-width "^4.2.0" + strip-ansi "^6.0.0" + wrap-ansi "^7.0.0" + clone@^2.1.1: version "2.1.2" resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f" @@ -3307,6 +3316,11 @@ gcs-resumable-upload@^3.1.3: pumpify "^2.0.0" stream-events "^1.0.4" +get-caller-file@^2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" + integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== + get-intrinsic@^1.0.2: version "1.1.1" resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.1.1.tgz#15f59f376f855c446963948f0d24cd3637b4abc6" @@ -5732,6 +5746,11 @@ request-progress@^3.0.0: dependencies: throttleit "^1.0.0" +require-directory@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42" + integrity sha1-jGStX9MNqxyXbiNE/+f3kqam30I= + resolve-from@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6" @@ -6262,7 +6281,7 @@ string-width@^1.0.1: is-fullwidth-code-point "^2.0.0" strip-ansi "^4.0.0" -string-width@^4.2.0: +string-width@^4.1.0, string-width@^4.2.0: version "4.2.2" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.2.tgz#dafd4f9559a7585cfba529c6a0a4f73488ebd4c5" integrity sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA== @@ -6923,6 +6942,15 @@ wrap-ansi@^3.0.1: string-width "^2.1.1" strip-ansi "^4.0.0" +wrap-ansi@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + wrappy@1: version "1.0.2" resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" @@ -6958,6 +6986,11 @@ y18n@^4.0.0: resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.1.tgz#8db2b83c31c5d75099bb890b23f3094891e247d4" integrity sha512-wNcy4NvjMYL8gogWWYAO7ZFWFfHcbdbE57tZO8e4cbpj8tfUcwrwqSl3ad8HxpYWCdXcJUCeKKZS62Av1affwQ== +y18n@^5.0.5: + version "5.0.5" + resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.5.tgz#8769ec08d03b1ea2df2500acef561743bbb9ab18" + integrity sha512-hsRUr4FFrvhhRH12wOdfs38Gy7k2FFzB9qgN9v3aLykRq0dRcdcpz5C9FxdS2NuhOrI/628b/KSTJ3rwHysYSg== + yallist@^3.0.2: version "3.1.1" resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd" @@ -6973,6 +7006,24 @@ yaml@^1.7.2: resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.0.tgz#3b593add944876077d4d683fee01081bd9fff31e" integrity sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg== +yargs-parser@^20.2.2: + version "20.2.7" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.7.tgz#61df85c113edfb5a7a4e36eb8aa60ef423cbc90a" + integrity sha512-FiNkvbeHzB/syOjIUxFDCnhSfzAL8R5vs40MgLFBorXACCOAEaWu0gRZl14vG8MR9AOJIZbmkjhusqBYZ3HTHw== + +yargs@^16.2.0: + version "16.2.0" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-16.2.0.tgz#1c82bf0f6b6a66eafce7ef30e376f49a12477f66" + integrity sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw== + dependencies: + cliui "^7.0.2" + escalade "^3.1.1" + get-caller-file "^2.0.5" + require-directory "^2.1.1" + string-width "^4.2.0" + y18n "^5.0.5" + yargs-parser "^20.2.2" + yauzl@^2.10.0: version "2.10.0" resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9" From 9264f141234c227932d5150e30ad79c834899724 Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Fri, 2 Apr 2021 22:51:35 -0400 Subject: [PATCH 4/6] Reworked the database seed script. --- dbseed.js | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/dbseed.js b/dbseed.js index 4935b588..422b9812 100644 --- a/dbseed.js +++ b/dbseed.js @@ -1,16 +1,35 @@ +/* eslint-env node */ + +// Seeding data is only for non-production environments. +if (process.env.NODE_ENV === 'production') { + throw new Error( + 'Data is not allowed to be seeded in a production environment.' + ) +} + +const path = require('path') + +// Load the local development configuration file. +require('dotenv').config({ path: path.join(__dirname, '.env.local') }) + const admin = require('firebase-admin') const faker = require('faker') +const yargs = require('yargs/yargs') +const { hideBin } = require('yargs/helpers') + +// The argument --seedSize=n can be passed in. +// If it is not passed in the default seed size is 10. +const { seedSize = 10 } = yargs(hideBin(process.argv)).argv +const { PROJECT_ID: projectId } = process.env -const projectId = 'protege-dev-env' -process.env.FIRESTORE_EMULATOR_HOST = 'localhost:8080' admin.initializeApp({ projectId }) const db = admin.firestore() -function getSeedData() { +async function seedDatabase() { try { - ;[...Array(10).keys()].map(() => - db.collection('jobs').add({ + for (let i = 0; i < seedSize; i++) { + const job = { approved: true, companyDescription: faker.lorem.paragraph(), companyEmail: faker.internet.email(), @@ -43,8 +62,11 @@ function getSeedData() { ]), status: faker.random.arrayElement(['viewed', 'sent']), // dateApplied: faker.date.recent(), - }) - ) + } + + await db.collection('jobs').add(job) + } + // eslint-disable-next-line no-console console.log('database seed was successful') } catch (error) { @@ -53,4 +75,4 @@ function getSeedData() { } } -getSeedData() +seedDatabase() From e58f237c23fe3be96e44e4acf744f8ddc2513900 Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Fri, 2 Apr 2021 23:03:57 -0400 Subject: [PATCH 5/6] Added missing new line to .env.local.template. --- .env.local.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.local.template b/.env.local.template index d9532f54..edca4445 100644 --- a/.env.local.template +++ b/.env.local.template @@ -6,4 +6,4 @@ STORAGE_BUCKET = "" MESSAGING_SENDER_ID = "" APP_ID = "" BASE_URL = "http://localhost:3000" -FIRESTORE_EMULATOR_HOST = "localhost:8080" \ No newline at end of file +FIRESTORE_EMULATOR_HOST = "localhost:8080" From e85a3f699340be095f093a36df5f8cc7bbb0bfd8 Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Fri, 2 Apr 2021 23:06:24 -0400 Subject: [PATCH 6/6] Renamed seed function to seedData --- dbseed.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dbseed.js b/dbseed.js index 422b9812..879d5185 100644 --- a/dbseed.js +++ b/dbseed.js @@ -26,7 +26,7 @@ admin.initializeApp({ projectId }) const db = admin.firestore() -async function seedDatabase() { +async function seedData() { try { for (let i = 0; i < seedSize; i++) { const job = { @@ -75,4 +75,4 @@ async function seedDatabase() { } } -seedDatabase() +seedData()