Skip to content

Commit 2a11548

Browse files
authored
Add startup scripts and environment switching for FriendlyEats quickstart (#727)
* Add new scripts and new environmemt.prod.ts file * Updated readme and package.json * Readme Change * Added more readme changes * Small Changes * Checking if projectID for prod * Added checking for projectID in config file * Changed name to projectConfig * Added script to check if config has porject id * Clean up after merge and modify README.md image * Space in README
1 parent 54465c7 commit 2a11548

9 files changed

Lines changed: 64 additions & 42 deletions

File tree

firestore/angular-rewrite/README.md

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Follow these steps to setup and run the quickstart:
4343
```bash
4444
npm start
4545
```
46-
1. Open [http://127.0.0.1:4200](http://127.0.0.1:4200) in your browser and try out the app!
46+
1. Open [http://localhost:4200](http://localhost:4200) in your browser and try out the app!
4747

4848
## Configure and run the app with the Firebase Console:
4949

@@ -59,49 +59,38 @@ Follow these steps to have a working version of the quickstart running with the
5959

6060
![Photo of firebaseConfig object](images/CopyWebConfig.png)
6161

62-
3. With the `firebaseConfig` copied, navigate to `src/environments/environments.ts` and paste the contents of the object into the `prod` field:
62+
3. With the `firebaseConfig` copied, navigate to `src/environments/environments.prod.ts` and paste the contents of the object into the `environment` object:
6363

64-
![Photo of `environments.ts` file with mock firebase web config info copied](images/environments-ts.png)
64+
![Photo of `environments.prod.ts` file with mock firebase web config info copied](images/environment-prod-ts.png)
6565

66-
4. On line 79 of `src/app/app.module.ts`, change your environment from `environments.local` to `environments.prod` in the `provideFirebaseApp` function call
67-
68-
![Photo of `environments.prod` selection in `src/app/app.module.ts`](images/ProdAppModule.png)
69-
70-
5. Back in the Firebase console, enable email and password authentication on your project by doing: **Authentication > SIGN-IN METHOD > Email > Email/Password > SAVE**
66+
4. Back in the Firebase console, enable email and password authentication on your project by doing: **Authentication > SIGN-IN METHOD > Email > Email/Password > SAVE**
7167

7268
![Photo of the enable email/password screen on Firebase Authentication page](images/Enable-Email.png)
7369

74-
6. In the Firebase console, enable Firestore on your project by clicking **Create Database** in the **Cloud Firestore** section of the console and answering all prompts.
70+
5. In the Firebase console, enable Firestore on your project by clicking **Create Database** in the **Cloud Firestore** section of the console and answering all prompts.
7571

7672
* When prompted, select "Start in Test Mode"
7773
7874
![Photo of Firebase Firestore Setup](images/EnableFirestore.png)
7975
80-
7. Simmilarly, enable Cloud Storage on your project by clicking **Get Started** in the **Storage** section of the console and answering all prompts.
76+
6. Simmilarly, enable Cloud Storage on your project by clicking **Get Started** in the **Storage** section of the console and answering all prompts.
8177
8278
* When prompted, select "Start in Test Mode"
8379
8480
![Photo of Firebase Storage Setup](images/EnableStorage.png)
8581
86-
8. Set the CLI to use the project you created in Step 1:
82+
7. Set the CLI to use the project you created in Step 1:
8783
8884
```bash
8985
firebase --use add
9086
```
9187
92-
9. Deploy the firebase security rules and indexes
93-
94-
```bash
95-
firebase deploy --only firestore
96-
```
97-
98-
> **Note:** If you've opted to set up a billing plan and wish to deploy functions as well, replace this command with simply `firebase deploy`.
99-
100-
10. Serve your Angular app and see it connect to the Firebase Console!
88+
8. Serve your Angular app and see it connect to the Firebase Console by opening [http://localhost:4200](http://localhost:4200) in your browser!
10189
10290
```bash
103-
ng serve
91+
npm run production
10492
```
93+
> **Note:** If you've opted to set up a billing plan and wish to deploy functions as well, replace the `firebase deploy --only firestore` on line 8 of `package.json` with `firebase deploy`.
10594
10695
11. (Optional) Populate production Firestore with mock data
10796
@@ -111,7 +100,7 @@ Follow these steps to have a working version of the quickstart running with the
111100
npm run populate-production
112101
```
113102
114-
> **Note:** To ensure that the script runs as intended, make sure that you have correctly populated the `environemnt.prod.ts` file with your Firebase credentials.
103+
> **Note:** To ensure that the script runs as intended, make sure that you have correctly populated the `environemnt.prod.ts` file with your Firebase credentials.
115104
116105
## Support
117106

firestore/angular-rewrite/angular.json

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,18 @@
2727
},
2828
"configurations": {
2929
"production": {
30-
"budgets": [
30+
"fileReplacements": [
3131
{
32-
"type": "initial",
33-
"maximumWarning": "500kb",
34-
"maximumError": "1mb"
35-
},
36-
{
37-
"type": "anyComponentStyle",
38-
"maximumWarning": "2kb",
39-
"maximumError": "4kb"
32+
"replace": "src/environments/environment.default.ts",
33+
"with": "src/environments/environment.prod.ts"
4034
}
4135
],
42-
"outputHashing": "all"
36+
"buildOptimizer": false,
37+
"optimization": false,
38+
"vendorChunk": true,
39+
"extractLicenses": false,
40+
"sourceMap": true,
41+
"namedChunks": true
4342
},
4443
"development": {
4544
"buildOptimizer": false,
@@ -48,21 +47,29 @@
4847
"extractLicenses": false,
4948
"sourceMap": true,
5049
"namedChunks": true
50+
},
51+
"local": {
52+
"buildOptimizer": false,
53+
"optimization": false,
54+
"vendorChunk": true,
55+
"extractLicenses": false,
56+
"sourceMap": true,
57+
"namedChunks": true
5158
}
5259
},
53-
"defaultConfiguration": "production"
60+
"defaultConfiguration": "local"
5461
},
5562
"serve": {
5663
"builder": "@angular-devkit/build-angular:dev-server",
5764
"configurations": {
5865
"production": {
5966
"browserTarget": "friendly-eats-quickstart:build:production"
6067
},
61-
"development": {
62-
"browserTarget": "friendly-eats-quickstart:build:development"
68+
"local":{
69+
"browserTarget": "friendly-eats-quickstart:build:local"
6370
}
6471
},
65-
"defaultConfiguration": "development"
72+
"defaultConfiguration": "local"
6673
},
6774
"extract-i18n": {
6875
"builder": "@angular-devkit/build-angular:extract-i18n",
-97 KB
Binary file not shown.
81.1 KB
Loading
-114 KB
Binary file not shown.

firestore/angular-rewrite/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
"version": "0.0.0",
44
"scripts": {
55
"ng": "ng",
6-
"start": "(cd functions && npm run build) && firebase --project demo-friendly-eats emulators:exec --import ./imported-firebase-data 'ng serve'",
7-
"populate-emulators": "cp src/environments/environment.ts scripts/environment.js && node scripts/PopulateFirestore.js",
6+
"start": "npm run pre-build && firebase --project demo-friendly-eats emulators:exec --import ./imported-firebase-data 'ng serve'",
7+
"emulators": "npm run pre-build && firebase --project demo-friendly-eats emulators:exec --import ./imported-firebase-data 'ng serve -c local'",
8+
"production": "npm run pre-build && firebase deploy --only firestore && npm run check-config",
9+
"check-config":"grep -q \"projectId\" \"src/environments/environment.prod.ts\" && ng serve -c production || echo \"No project id in configuration file!\"",
10+
"pre-build": "(cd functions && npm run build)",
11+
"populate-emulators": "cp src/environments/environment.default.ts scripts/environment.js && node scripts/PopulateFirestore.js",
812
"populate-production": "cp src/environments/environment.prod.ts scripts/environment.js && node scripts/PopulateFirestore.js",
913
"build": "ng build",
1014
"watch": "ng build --watch --configuration development",

firestore/angular-rewrite/src/app/app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { provideAuth, getAuth, connectAuthEmulator } from '@angular/fire/auth';
3030
import { provideFirestore, getFirestore } from '@angular/fire/firestore';
3131
import { provideFunctions, getFunctions } from '@angular/fire/functions';
3232
import { provideStorage, getStorage } from '@angular/fire/storage'
33-
import { projectConfig } from 'src/environments/environment';
33+
import { projectConfig } from '../environments/environment.default';
3434
import { HomepageComponent } from './homepage/homepage.component';
3535
import { RestuarantPageComponent } from './restuarant-page/restuarant-page.component';
3636
import { MatIconModule } from '@angular/material/icon';

firestore/angular-rewrite/src/environments/environment.ts renamed to firestore/angular-rewrite/src/environments/environment.default.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616

1717

1818
/** If connecting to a live Firebase project (one that you set up in the
19-
* Firebase console) put your config vars into the `prod` field object here
20-
* and change the `initializeApp` value in `app.module.ts` to `environment.prod`.
19+
* Firebase console) put your config vars into the `environment.prod.ts` file.
2120
* Otherwise, leave untouched to enable connection to demo project and emulators.
2221
*/
23-
2422
export const projectConfig = {
2523
projectId: 'demo-friendly-eats',
2624
apiKey: 'API_KEY_UNUSED'
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
18+
/** If connecting to a live Firebase project (one that you set up in the
19+
* Firebase console) put your config vars into the the object in this file.
20+
* Otherwise, leave untouched to enable connection to demo project and emulators.
21+
* For more information about generating, finding, or using project config
22+
* objects, visit https://support.google.com/firebase/answer/7015592.
23+
*/
24+
export const projectConfig = {}

0 commit comments

Comments
 (0)