Skip to content

Commit 5867eeb

Browse files
committed
Updating the schematic for the list depreciation
1 parent f3b7bd8 commit 5867eeb

File tree

4 files changed

+24
-37
lines changed

4 files changed

+24
-37
lines changed

src/schematics/deploy/actions.spec.ts

+8-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { JsonObject, logging } from '@angular-devkit/core';
2-
import { BuilderContext, BuilderRun, ScheduleOptions, Target, } from '@angular-devkit/architect/src/index2';
3-
import { FirebaseTools, FirebaseDeployConfig } from 'schematics/interfaces';
2+
import { BuilderContext, BuilderRun, ScheduleOptions, Target, } from '@angular-devkit/architect';
3+
import { FirebaseTools, FirebaseDeployConfig } from '../interfaces';
44
import deploy from './actions';
55

66

@@ -13,21 +13,10 @@ const PROJECT = 'pirojok-project';
1313
describe('Deploy Angular apps', () => {
1414
beforeEach(() => initMocks());
1515

16-
it('should check if the user is authenticated by invoking list', async () => {
17-
const spy = spyOn(firebaseMock, 'list');
18-
const spyLogin = spyOn(firebaseMock, 'login');
16+
it('should call login', async () => {
17+
const spy = spyOn(firebaseMock, 'login');
1918
await deploy(firebaseMock, context, 'host', FIREBASE_PROJECT);
2019
expect(spy).toHaveBeenCalled();
21-
expect(spyLogin).not.toHaveBeenCalled();
22-
});
23-
24-
it('should invoke login if list rejects', async () => {
25-
firebaseMock.list = () => Promise.reject();
26-
const spy = spyOn(firebaseMock, 'list').and.callThrough();
27-
const spyLogin = spyOn(firebaseMock, 'login');
28-
await deploy(firebaseMock, context, 'host', FIREBASE_PROJECT);
29-
expect(spy).toHaveBeenCalled();
30-
expect(spyLogin).toHaveBeenCalled();
3120
});
3221

3322
it('should invoke the builder', async () => {
@@ -75,12 +64,14 @@ describe('Deploy Angular apps', () => {
7564
const initMocks = () => {
7665
firebaseMock = {
7766
login: () => Promise.resolve(),
78-
list: () => Promise.resolve([]),
67+
projects: {
68+
list: () => Promise.resolve([]),
69+
},
7970
deploy: (_: FirebaseDeployConfig) => Promise.resolve(),
8071
use: () => Promise.resolve()
8172
};
8273

83-
context = {
74+
context = <any>{
8475
target: {
8576
configuration: 'production',
8677
project: PROJECT,

src/schematics/deploy/actions.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,8 @@ export default async function deploy(
1111
throw new Error("Cannot find firebase project for your app in .firebaserc");
1212
}
1313

14-
try {
15-
await firebaseTools.list();
16-
} catch (e) {
17-
context.logger.warn(
18-
"🚨 You're not logged into Firebase. Logging you in..."
19-
);
20-
await firebaseTools.login();
21-
}
14+
await firebaseTools.login();
15+
2216
if (!context.target) {
2317
throw new Error("Cannot execute the build target");
2418
}

src/schematics/interfaces.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
export interface Project {
2+
projectId: string;
3+
projectNumber: string;
4+
displayName: string;
25
name: string;
3-
id: string;
4-
permission: "edit" | "view" | "own";
6+
resources: { [key:string]: string }
57
}
68

79
export interface FirebaseDeployConfig {
@@ -12,7 +14,9 @@ export interface FirebaseDeployConfig {
1214
export interface FirebaseTools {
1315
login(): Promise<void>;
1416

15-
list(): Promise<Project[]>;
17+
projects: {
18+
list(): Promise<Project[]>;
19+
}
1620

1721
deploy(config: FirebaseDeployConfig): Promise<any>;
1822

src/schematics/utils.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import { readFileSync } from "fs";
22
import { FirebaseRc, Project } from "./interfaces";
33
import { join } from "path";
44

5-
export function listProjects() {
5+
export async function listProjects() {
66
const firebase = require('firebase-tools');
7-
return firebase.list().catch(
8-
/* If list failed, then login and try again. */
9-
() => firebase.login().then(() => firebase.list())
10-
);
7+
await firebase.login();
8+
return firebase.projects.list();
119
}
1210

1311
// `fuzzy` passes either the original list of projects or an internal object
@@ -22,7 +20,7 @@ const searchProjects = (projects: Project[]) => {
2220
require('fuzzy')
2321
.filter(input, projects, {
2422
extract(el: Project) {
25-
return `${el.id} ${el.name} ${el.permission}`;
23+
return `${el.projectId} ${el.displayName}`;
2624
}
2725
})
2826
.map((result: Project | { original: Project }) => {
@@ -33,9 +31,9 @@ const searchProjects = (projects: Project[]) => {
3331
original = result.original;
3432
}
3533
return {
36-
name: `${original.id} (${original.name})`,
37-
title: original.name,
38-
value: original.id
34+
name: `${original.displayName} (${original.projectId})`,
35+
title: original.displayName,
36+
value: original.projectId
3937
};
4038
})
4139
);

0 commit comments

Comments
 (0)