Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(schematics): rewrite projectFromRc and add spec file #3284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nontangent wants to merge 3 commits into angular:main
base: main
Choose a base branch
Loading
from nontangent:fix/project-from-rc-bug
Open
Show file tree
Hide file tree
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
View file Open in desktop
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
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
};

/**
Expand Down

AltStyle によって変換されたページ (->オリジナル) /