From 0c386ef88e6959ef2a5a4a3daf57266e9999df96 Mon Sep 17 00:00:00 2001 From: George Grigorian Date: Sun, 29 Mar 2020 23:11:56 +1100 Subject: [PATCH 1/3] feat(ng-deploy): add option to specify firebaseProject (#2281) --- src/schematics/deploy/actions.ts | 4 +++- src/schematics/deploy/builder.ts | 2 +- src/schematics/deploy/schema.json | 4 ++++ src/schematics/interfaces.ts | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/schematics/deploy/actions.ts b/src/schematics/deploy/actions.ts index 13489bff2..dea2e5bb2 100644 --- a/src/schematics/deploy/actions.ts +++ b/src/schematics/deploy/actions.ts @@ -159,7 +159,9 @@ export default async function deploy( } try { - await firebaseTools.use(firebaseProject, { project: firebaseProject }); + await firebaseTools.use(firebaseProject, { project: firebaseProject }).then(() => { + console.log(`🔥 Your configured Firebase project is '${firebaseProject}'`); + }); } catch (e) { throw new Error(`Cannot select firebase project '${firebaseProject}'`); } diff --git a/src/schematics/deploy/builder.ts b/src/schematics/deploy/builder.ts index 19d328bdb..a02e56248 100644 --- a/src/schematics/deploy/builder.ts +++ b/src/schematics/deploy/builder.ts @@ -31,7 +31,7 @@ export default createBuilder( const projectTargets = workspace.getProjectTargets(context.target.project); - const firebaseProject = getFirebaseProjectName( + const firebaseProject = options.firebaseProject || getFirebaseProjectName( context.workspaceRoot, context.target.project ); diff --git a/src/schematics/deploy/schema.json b/src/schematics/deploy/schema.json index a48deed07..cc5ffa902 100644 --- a/src/schematics/deploy/schema.json +++ b/src/schematics/deploy/schema.json @@ -9,6 +9,10 @@ "description": "Target to build.", "pattern": "^[^:\\s]+:[^:\\s]+(:[^\\s]+)?$" }, + "firebaseProject": { + "type": "string", + "description": "The firebase project name or project alias to use when deploying" + }, "preview": { "type": "boolean", "description": "Do not deploy the application, just set up the Firebase Function in the project output directory. Can be used for testing the Firebase Function with `firebase serve`." diff --git a/src/schematics/interfaces.ts b/src/schematics/interfaces.ts index 20dad60f3..31240e75b 100644 --- a/src/schematics/interfaces.ts +++ b/src/schematics/interfaces.ts @@ -50,6 +50,7 @@ export interface FirebaseRc { export interface DeployBuilderSchema { buildTarget?: string; + firebaseProject?: string; preview?: boolean; universalBuildTarget?: string; ssr?: boolean; From 333d962c6d5570f6f1d4807cbc13df5dd333b649 Mon Sep 17 00:00:00 2001 From: George Grigorian Date: Mon, 30 Mar 2020 23:01:59 +1100 Subject: [PATCH 2/3] docs(ng-deploy): add info about configuring deploy targets and build targets There has also been a minor code style change in how feedback is logged during deploy. My initial commit used console.log, whereas the proper way uses context.logger... this has been fixed. --- docs/deploy/getting-started.md | 34 ++++++++++++++++++++++++++++++++ src/schematics/deploy/actions.ts | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/docs/deploy/getting-started.md b/docs/deploy/getting-started.md index 1158989ae..f296d5bd3 100644 --- a/docs/deploy/getting-started.md +++ b/docs/deploy/getting-started.md @@ -88,3 +88,37 @@ We'll create the function and a `package.json` in your project output directory. ## Step 3: customization To customize the deployment flow, you can use the configuration files you're already familiar with from `firebase-tools`. You can find more in the [firebase documentation](https://firebase.google.com/docs/hosting/full-config). + +### Configuration Options + +If you have multiple build targets and deploy targets, it is possible to specify them in your `angular.json` or `workspace.json`. + +It is possible to use either your project name or project alias in `firebaseProject`. The setting provided here is equivalent to passing a project name or alias to `firebase deploy --project projectNameOrAlias`. The uppercase `-P` flag is also an alias for `--project` when using Firebase CLI. + +The `buildTarget` simply points to an existing build configuration for your project. Most projects have a default configuration and a production configuration (commonly activated by using the `--prod` flag) but it is possible to specify as many build configurations as needed. + +You may specify a `buildTarget` and `firebaseProject` in your `options` as follows: + +```json +"deploy": { + "builder": "@angular/fire:deploy", + "options": { + "buildTarget": "projectName:build", + "firebaseProject": "developmentProject" + }, + "configurations": { + "production": { + "buildTarget": "projectName:build:production", + "firebaseProject": "productionProject" + } + } +} +``` + +The above configuration specifies the following: + +1. `ng deploy` will deploy the default project with default configuration. +2. `ng deploy projectName` will deploy the specified project with default configuration. +3. `ng deploy projectName --prod` or `ng deploy projectName --configuration='production'` will deploy `projectName` with production build settings to your production environment. + +All of the options are optional. If you do not specify a `buildTarget`, it defaults to a production build (`projectName:build:production`). If you do not specify a `firebaseProject`, it defaults to the first matching deploy target found in your `.firebaserc` (where your projectName is the same as your Firebase deploy target name). The `configurations` section is also optional. diff --git a/src/schematics/deploy/actions.ts b/src/schematics/deploy/actions.ts index dea2e5bb2..8f6532874 100644 --- a/src/schematics/deploy/actions.ts +++ b/src/schematics/deploy/actions.ts @@ -160,7 +160,7 @@ export default async function deploy( try { await firebaseTools.use(firebaseProject, { project: firebaseProject }).then(() => { - console.log(`🔥 Your configured Firebase project is '${firebaseProject}'`); + context.logger.info(`🔥 Your configured Firebase project is '${firebaseProject}'`); }); } catch (e) { throw new Error(`Cannot select firebase project '${firebaseProject}'`); From 8bfcd375f5f3d06c0686a40c040f3cd892657bf0 Mon Sep 17 00:00:00 2001 From: George Grigorian Date: Fri, 1 May 2020 15:02:33 +1000 Subject: [PATCH 3/3] fix(ng-deploy): improvements as per (#2366) As suggested in comments in #2366, I have made some small improvements to existing changes pending in this PR. --- src/schematics/deploy/actions.ts | 5 ++--- src/schematics/deploy/schema.json | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/schematics/deploy/actions.ts b/src/schematics/deploy/actions.ts index 975192f61..449bf485d 100644 --- a/src/schematics/deploy/actions.ts +++ b/src/schematics/deploy/actions.ts @@ -234,9 +234,8 @@ export default async function deploy( } try { - await firebaseTools.use(firebaseProject, { project: firebaseProject }).then(() => { - context.logger.info(`🔥 Your configured Firebase project is '${firebaseProject}'`); - }); + await firebaseTools.use(firebaseProject, { project: firebaseProject }); + context.logger.info(`🔥 Your configured Firebase project is '${firebaseProject}'`); } catch (e) { throw new Error(`Cannot select firebase project '${firebaseProject}'`); } diff --git a/src/schematics/deploy/schema.json b/src/schematics/deploy/schema.json index cc5ffa902..2a49ab81c 100644 --- a/src/schematics/deploy/schema.json +++ b/src/schematics/deploy/schema.json @@ -11,7 +11,7 @@ }, "firebaseProject": { "type": "string", - "description": "The firebase project name or project alias to use when deploying" + "description": "The Firebase project name or project alias to use when deploying" }, "preview": { "type": "boolean",