-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathgetDefaultHostingSite.ts
More file actions
36 lines (34 loc) · 1.17 KB
/
getDefaultHostingSite.ts
File metadata and controls
36 lines (34 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { FirebaseError } from "./error";
import { SiteType, listSites } from "./hosting/api";
import { logger } from "./logger";
import { getFirebaseProject } from "./management/projects";
import { needProjectId } from "./projectUtils";
import { last } from "./utils";
export const errNoDefaultSite = new FirebaseError(
"Could not determine the default site for the project.",
);
/**
* Tries to determine the default hosting site for a project, else falls back to projectId.
* @param options The command-line options object
* @return The hosting site ID
*/
export async function getDefaultHostingSite(options: { projectId?: string }): Promise<string> {
const projectId = needProjectId(options);
const project = await getFirebaseProject(projectId);
let site = project.resources?.hostingSite;
if (!site) {
logger.debug(`the default site does not exist on the Firebase project; asking Hosting.`);
const sites = await listSites(projectId);
for (const s of sites) {
if (s.type === SiteType.DEFAULT_SITE) {
site = last(s.name.split("/"));
break;
}
}
if (!site) {
throw errNoDefaultSite;
}
return site;
}
return site;
}