Skip to content

Commit dd92869

Browse files
feat(schematics): support FIREBASE_TOKEN for ng deploy (#2327)
Co-authored-by: James Daniels <[email protected]>
1 parent c193afa commit dd92869

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

src/schematics/deploy/actions.jasmine.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ const PROJECT = 'pirojok-project';
1313
const STATIC_BUILD_TARGET: BuildTarget = {
1414
name: `${PROJECT}:build:production`
1515
};
16+
17+
const FIREBASE_TOKEN = 'kkasllkascnkjnskjsdcskdckskdksdkjc';
18+
1619
const SERVER_BUILD_TARGET: BuildTarget = {
1720
name: `${PROJECT}:server:production`
1821
};
@@ -83,6 +86,12 @@ describe('Deploy Angular apps', () => {
8386
expect(spy).toHaveBeenCalled();
8487
});
8588

89+
it('should not call login', async () => {
90+
const spy = spyOn(firebaseMock, 'login');
91+
await deploy(firebaseMock, context, STATIC_BUILD_TARGET, undefined, FIREBASE_PROJECT, false, FIREBASE_TOKEN);
92+
expect(spy).not.toHaveBeenCalled();
93+
});
94+
8695
it('should invoke the builder', async () => {
8796
const spy = spyOn(context, 'scheduleTarget').and.callThrough();
8897
await deploy(firebaseMock, context, STATIC_BUILD_TARGET, undefined, FIREBASE_PROJECT, false);
@@ -107,11 +116,12 @@ describe('Deploy Angular apps', () => {
107116

108117
it('should invoke firebase.deploy', async () => {
109118
const spy = spyOn(firebaseMock, 'deploy').and.callThrough();
110-
await deploy(firebaseMock, context, STATIC_BUILD_TARGET, undefined, FIREBASE_PROJECT, false);
119+
await deploy(firebaseMock, context, STATIC_BUILD_TARGET, undefined, FIREBASE_PROJECT, false, FIREBASE_TOKEN);
111120
expect(spy).toHaveBeenCalled();
112121
expect(spy).toHaveBeenCalledWith({
113122
cwd: 'cwd',
114-
only: 'hosting:' + PROJECT
123+
only: 'hosting:' + PROJECT,
124+
token: FIREBASE_TOKEN
115125
});
116126
});
117127

@@ -141,7 +151,7 @@ describe('universal deployment', () => {
141151

142152
it('should create a firebase function', async () => {
143153
const spy = spyOn(fsHost, 'writeFileSync');
144-
await deployToFunction(firebaseMock, context, '/home/user', STATIC_BUILD_TARGET, SERVER_BUILD_TARGET, false, fsHost);
154+
await deployToFunction(firebaseMock, context, '/home/user', STATIC_BUILD_TARGET, SERVER_BUILD_TARGET, false, undefined, fsHost);
145155

146156
expect(spy).toHaveBeenCalledTimes(2);
147157

@@ -154,7 +164,7 @@ describe('universal deployment', () => {
154164

155165
it('should rename the index.html file in the nested dist', async () => {
156166
const spy = spyOn(fsHost, 'renameSync');
157-
await deployToFunction(firebaseMock, context, '/home/user', STATIC_BUILD_TARGET, SERVER_BUILD_TARGET, false, fsHost);
167+
await deployToFunction(firebaseMock, context, '/home/user', STATIC_BUILD_TARGET, SERVER_BUILD_TARGET, false, undefined, fsHost);
158168

159169
expect(spy).toHaveBeenCalledTimes(1);
160170

@@ -168,7 +178,7 @@ describe('universal deployment', () => {
168178

169179
it('should invoke firebase.deploy', async () => {
170180
const spy = spyOn(firebaseMock, 'deploy');
171-
await deployToFunction(firebaseMock, context, '/home/user', STATIC_BUILD_TARGET, SERVER_BUILD_TARGET, false, fsHost);
181+
await deployToFunction(firebaseMock, context, '/home/user', STATIC_BUILD_TARGET, SERVER_BUILD_TARGET, false, undefined, fsHost);
172182

173183
expect(spy).toHaveBeenCalledTimes(1);
174184
});

src/schematics/deploy/actions.ts

+19-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const deployToHosting = (
1919
firebaseTools: FirebaseTools,
2020
context: BuilderContext,
2121
workspaceRoot: string,
22-
preview: boolean
22+
preview: boolean,
23+
firebaseToken?: string,
2324
) => {
2425

2526
if (preview) {
@@ -40,7 +41,8 @@ const deployToHosting = (
4041
return firebaseTools.deploy({
4142
// tslint:disable-next-line:no-non-null-assertion
4243
only: 'hosting:' + context.target!.project,
43-
cwd: workspaceRoot
44+
cwd: workspaceRoot,
45+
token: firebaseToken,
4446
});
4547
} else {
4648
return Promise.resolve();
@@ -52,7 +54,8 @@ const deployToHosting = (
5254
return firebaseTools.deploy({
5355
// tslint:disable-next-line:no-non-null-assertion
5456
only: 'hosting:' + context.target!.project,
55-
cwd: workspaceRoot
57+
cwd: workspaceRoot,
58+
token: firebaseToken,
5659
});
5760

5861
}
@@ -118,7 +121,8 @@ export const deployToFunction = async (
118121
staticBuildTarget: BuildTarget,
119122
serverBuildTarget: BuildTarget,
120123
preview: boolean,
121-
fsHost: FSHost = defaultFsHost
124+
firebaseToken?: string,
125+
fsHost: FSHost = defaultFsHost,
122126
) => {
123127
if (!satisfies(process.versions.node, getVersionRange(NODE_VERSION))) {
124128
context.logger.warn(
@@ -195,7 +199,8 @@ export const deployToFunction = async (
195199
return firebaseTools.deploy({
196200
// tslint:disable-next-line:no-non-null-assertion
197201
only: `hosting:${context.target!.project},functions:ssr`,
198-
cwd: workspaceRoot
202+
cwd: workspaceRoot,
203+
token: firebaseToken,
199204
});
200205
}
201206
};
@@ -206,9 +211,12 @@ export default async function deploy(
206211
staticBuildTarget: BuildTarget,
207212
serverBuildTarget: BuildTarget | undefined,
208213
firebaseProject: string,
209-
preview: boolean
214+
preview: boolean,
215+
firebaseToken?: string,
210216
) {
211-
await firebaseTools.login();
217+
if (!firebaseToken) {
218+
await firebaseTools.login();
219+
}
212220

213221
if (!context.target) {
214222
throw new Error('Cannot execute the build target');
@@ -258,14 +266,16 @@ export default async function deploy(
258266
context.workspaceRoot,
259267
staticBuildTarget,
260268
serverBuildTarget,
261-
preview
269+
preview,
270+
firebaseToken,
262271
);
263272
} else {
264273
await deployToHosting(
265274
firebaseTools,
266275
context,
267276
context.workspaceRoot,
268-
preview
277+
preview,
278+
firebaseToken,
269279
);
270280
}
271281

src/schematics/deploy/builder.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export default createBuilder(
4141
staticBuildTarget,
4242
serverBuildTarget,
4343
firebaseProject,
44-
!!options.preview
44+
!!options.preview,
45+
process.env.FIREBASE_TOKEN,
4546
);
4647
} catch (e) {
4748
console.error('Error when trying to deploy: ');

src/schematics/interfaces.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface Project {
99
export interface FirebaseDeployConfig {
1010
cwd: string;
1111
only?: string;
12+
token?: string;
1213
}
1314

1415
export interface FirebaseTools {

0 commit comments

Comments
 (0)