Skip to content

Commit 1440fb1

Browse files
authored
feat(deploy): target support for multi-site deploy options (#2726)
1 parent ca6eac2 commit 1440fb1

File tree

4 files changed

+79
-10
lines changed

4 files changed

+79
-10
lines changed

docs/deploy/getting-started.md

+62-1
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,65 @@ The above configuration specifies the following:
140140
2. `ng deploy projectName` will deploy the specified project with default configuration.
141141
3. `ng deploy projectName --prod` or `ng deploy projectName --configuration='production'` will deploy `projectName` with production build settings to your production environment.
142142

143-
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.
143+
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.
144+
145+
### Working with multiple project sites
146+
147+
For example, if you have muti sites config in firebase.json like this:
148+
```
149+
{
150+
"hosting": [
151+
{
152+
"target": "custom-site",
153+
"public": "public/my-custom-site",
154+
"ignore": [
155+
"firebase.json",
156+
"**/.*",
157+
"**/node_modules/**"
158+
],
159+
"rewrites": [
160+
{
161+
"source": "**",
162+
"destination": "/index.html"
163+
}
164+
]
165+
}
166+
],
167+
```
168+
169+
If you have multiple build targets and deploy targets, it is possible to specify them in your `angular.json` or `workspace.json`.
170+
171+
It is possible to use either your project name or project alias in `siteTarget`.
172+
173+
You may specify a `siteTarget` in your `options` as follows:
174+
175+
```json
176+
"deploy": {
177+
"builder": "@angular/fire:deploy",
178+
"options": {
179+
"buildTarget": "projectName:build",
180+
"firebaseProject": "developmentProject",
181+
"siteTarget": "yourDefaultSiteTarget"
182+
},
183+
"configurations": {
184+
"production": {
185+
"buildTarget": "projectName:build:production",
186+
"firebaseProject": "productionProject",
187+
"siteTarget": "yourProdSiteTarget"
188+
},
189+
"storybook": {
190+
"buildTarget": "projectName:build-storybook",
191+
"firebaseProject": "developmentProject",
192+
"siteTarget": "yourStorybookSiteTarget"
193+
}
194+
}
195+
}
196+
```
197+
198+
The above configuration specifies the following:
199+
200+
1. `ng deploy` will deploy the default project with default configuration.
201+
2. `ng deploy projectName` will deploy the specified project with default configuration.
202+
3. `ng deploy projectName --configuration=storybook --siteTarget=mySiteTarget` will deploy `projectName` to `mySiteTarget` with configuration`storybook`.
203+
204+
All of the options are optional

src/schematics/deploy/actions.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,16 @@ const deployToHosting = async (
7070
options: DeployBuilderOptions,
7171
firebaseToken?: string,
7272
) => {
73+
74+
// tslint:disable-next-line:no-non-null-assertion
75+
const siteTarget = options.target ?? context.target!.project;
7376

7477
if (options.preview) {
7578

7679
await firebaseTools.serve({
7780
port: DEFAULT_EMULATOR_PORT,
7881
host: DEFAULT_EMULATOR_HOST,
79-
// tslint:disable-next-line:no-non-null-assertion
80-
targets: [`hosting:${context.target!.project}`],
82+
targets: [`hosting:${siteTarget}`],
8183
nonInteractive: true,
8284
projectRoot: workspaceRoot,
8385
});
@@ -93,8 +95,7 @@ const deployToHosting = async (
9395
}
9496

9597
return await firebaseTools.deploy({
96-
// tslint:disable-next-line:no-non-null-assertion
97-
only: 'hosting:' + context.target!.project,
98+
only: `hosting:${siteTarget}`,
9899
cwd: workspaceRoot,
99100
token: firebaseToken,
100101
nonInteractive: true,
@@ -222,14 +223,14 @@ export const deployToFunction = async (
222223
}
223224

224225
// tslint:disable-next-line:no-non-null-assertion
225-
const project = context.target!.project;
226+
const siteTarget = options.target ?? context.target!.project;
226227

227228
if (options.preview) {
228229

229230
await firebaseTools.serve({
230231
port: DEFAULT_EMULATOR_PORT,
231232
host: DEFAULT_EMULATOR_HOST,
232-
targets: [`hosting:${project}`, `functions:${functionName}`],
233+
targets: [`hosting:${siteTarget}`, `functions:${functionName}`],
233234
nonInteractive: true,
234235
projectRoot: workspaceRoot,
235236
});
@@ -244,7 +245,7 @@ export const deployToFunction = async (
244245
}
245246

246247
return await firebaseTools.deploy({
247-
only: `hosting:${project},functions:${functionName}`,
248+
only: `hosting:${siteTarget},functions:${functionName}`,
248249
cwd: workspaceRoot,
249250
token: firebaseToken,
250251
nonInteractive: true,
@@ -349,10 +350,12 @@ export const deployToCloudRun = async (
349350
await spawnAsync(`gcloud builds submit ${cloudRunOut} --tag gcr.io/${options.firebaseProject}/${serviceId} --project ${options.firebaseProject} --quiet`);
350351
await spawnAsync(`gcloud run deploy ${serviceId} --image gcr.io/${options.firebaseProject}/${serviceId} --project ${options.firebaseProject} ${deployArguments.join(' ')} --platform managed --allow-unauthenticated --region=${options.region} --quiet`);
351352

353+
// tslint:disable-next-line:no-non-null-assertion
354+
const siteTarget = options.target ?? context.target!.project;
355+
352356
// TODO deploy cloud run
353357
return await firebaseTools.deploy({
354-
// tslint:disable-next-line:no-non-null-assertion
355-
only: `hosting:${context.target!.project}`,
358+
only: `hosting:${siteTarget}`,
356359
cwd: workspaceRoot,
357360
token: firebaseToken,
358361
nonInteractive: true,

src/schematics/deploy/schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
"type": "string",
4242
"description": "The Firebase project name or project alias to use when deploying"
4343
},
44+
"target": {
45+
"type": "string",
46+
"description": "The Firebase hosting target in firebase.json for multi-site"
47+
},
4448
"firebaseHostingSite": {
4549
"type": "string",
4650
"description": "The Firebase Hosting site to deploy to"

src/schematics/interfaces.ts

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export interface DeployBuilderSchema {
166166
firebaseProject?: string;
167167
firebaseHostingSite?: string;
168168
preview?: boolean;
169+
target?: boolean;
169170
universalBuildTarget?: string;
170171
serverTarget?: string;
171172
prerenderTarget?: string;

0 commit comments

Comments
 (0)