Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions src/schematics/utils.jasmine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { projectFromRc } from './utils';

describe('projectFromRc()', () => {
it('Given `projects.default`, should return default project', () => {
const FIRE_BASE_RC = `{
"targets": {
"project_prod": {
"hosting": {
"app_1": [
"target_1_prod"
],
"app_2": [
"target_2_prod"
]
}
},
"project_stg": {
"hosting": {
"app_1": [
"target_1_stg"
],
"app_2": [
"target_2_stg"
]
}
}
},
"projects": {
"default": "project_stg"
}
}`;
expect(projectFromRc(JSON.parse(FIRE_BASE_RC), 'app_1')).toEqual(['project_stg', 'target_1_stg']);
});

it('Given no `projects.default`, should return first matched project', () => {
const FIRE_BASE_RC = `{
"targets": {
"project_prod": {
"hosting": {
"app_1": [
"target_1_prod"
],
"app_2": [
"target_2_prod"
]
}
},
"project_stg": {
"hosting": {
"app_1": [
"target_1_stg"
],
"app_2": [
"target_2_stg"
]
}
}
}
}`;
expect(projectFromRc(JSON.parse(FIRE_BASE_RC), 'app_1')).toEqual(['project_prod', 'target_1_prod']);
});

it('Given empty targets, return [undefined, undefined]', () => {
const FIRE_BASE_RC = `{
"targets": {}
}`;
expect(projectFromRc(JSON.parse(FIRE_BASE_RC), 'app_1')).toEqual([undefined, undefined]);
});
});
18 changes: 11 additions & 7 deletions src/schematics/utils.ts
Original file line number Diff line number Diff line change
@@ -95,13 +95,17 @@ export function getFirebaseProjectNameFromFs(
}
}

const projectFromRc = (rc: FirebaseRc, target: string): [string|undefined, string|undefined] => {
const defaultProject = rc.projects?.default;
const project = Object.keys(rc.targets || {}).find(
project => !!rc.targets?.[project]?.hosting?.[target]
);
const site = project && rc.targets?.[project]?.hosting?.[target]?.[0];
return [project || defaultProject, site];
export const projectFromRc = (rc: FirebaseRc, target: string): [string|undefined, string|undefined] => {
if (!rc.targets) {
return [undefined, undefined];
}

const project = rc.projects?.default || Object.keys(rc.targets)[0];
if (!project) {
return [undefined, undefined];
}

return [project, rc.targets[project].hosting[target][0]];
};

/**