Skip to content

Add script to generate mock data for FriendlyEats quickstart #728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 1, 2023

Conversation

ABradham
Copy link
Contributor

@ABradham ABradham commented Jul 31, 2023

This PR adds a new scripts directory (scripts/) that includes scripts to

  1. Pull the specified Firebase environment (production or local)
  2. Generate mock Restaurant data
  3. Send generated restaurant data to the relevant Firestore database (emulated or on Firebase console)

@ABradham ABradham self-assigned this Jul 31, 2023
@ABradham ABradham requested review from christhompsongoogle, HYACCCINT and kroikie and removed request for christhompsongoogle July 31, 2023 16:27
},
prod: {}
projectId: 'demo-friendly-eats',
apiKey: '[FIREBASE_API_KEY]'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This seems like we're inviting the developer to add their own, whereas any string value works here. Perhaps we should use something obviously fake like "api_key_unused"

@@ -0,0 +1,14 @@
{
"name": "scripts",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to put this a level up in the root package.json? Also scripts at the top level beside src (instead of nested within it)

That helps keep all commands discoverable at a single level. Bonus if we can accomplish the same with functions

var city = getRandomItem(data.cities);
var price = Math.floor(Math.random() * 4) + 1;
var photoID = Math.floor(Math.random() * 22) + 1;
var photo =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bypasses the storage emulator - which isn't a big deal but it removes the need to use the storage emulator in this case. Let's add a TODO to download/store the images in a follow-up PR

{
"name": "scripts",
"version": "1.0.0",
"description": "A script to send mock data to the prod firebase console",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this package.json anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so; I'm importing node modules using the import syntax in PopulateFirestore.js, and when I attempt to run the script after removing the package.json, I get an error that reads

SyntaxError: Cannot use import statement outside a module

@@ -103,6 +103,14 @@ Follow these steps to have a working version of the quickstart running with the
ng serve
```

11. (Optional) Populate production Firestore with mock data

Now that the application is live on the Firebase console, you likely want to add some data to your production Firestore database so that you can see the application in action. Rather than manually adding restaurants and reviews, a convenice script is available to populate your production Firestore database. Run the following command (defined in the `Firestore/` directory's `package.json`) to add mock data:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's note that this requires your configuration to exist in the config file

@@ -20,10 +20,8 @@
* and change the `initializeApp` value in `app.module.ts` to `environment.prod`.
* Otherwise, leave untouched to enable connection to demo project and emulators.
*/

export const environment = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

projectConfig

@ABradham ABradham merged commit 54465c7 into master Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants