-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathhosting-sites-create.ts
More file actions
44 lines (38 loc) · 1.66 KB
/
hosting-sites-create.ts
File metadata and controls
44 lines (38 loc) · 1.66 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
37
38
39
40
41
42
43
44
import { bold } from "colorette";
import { Command } from "../command";
import { pickHostingSiteName } from "../hosting/interactive";
import { logLabeledSuccess } from "../utils";
import { logger } from "../logger";
import { needProjectId } from "../projectUtils";
import { Options } from "../options";
import { requirePermissions } from "../requirePermissions";
import { createSite, Site } from "../hosting/api";
import { FirebaseError } from "../error";
const LOG_TAG = "hosting:sites";
export const command = new Command("hosting:sites:create [siteId]")
.description("create a Firebase Hosting site")
.option("--app <appId>", "specify an existing Firebase Web App ID")
.before(requirePermissions, ["firebasehosting.sites.update"])
.action(async (siteId: string | undefined, options: Options & { app: string }): Promise<Site> => {
const projectId = needProjectId(options);
const appId = options.app;
if (options.nonInteractive && !siteId) {
throw new FirebaseError(`${bold("siteId")} is required in a non-interactive environment`);
}
siteId = await pickHostingSiteName(siteId ?? "", options);
const site = await createSite(projectId, siteId, appId);
logger.info();
logLabeledSuccess(
LOG_TAG,
`Site ${bold(siteId)} has been created in project ${bold(projectId)}.`,
);
if (appId) {
logLabeledSuccess(LOG_TAG, `Site ${bold(siteId)} has been linked to web app ${bold(appId)}`);
}
logLabeledSuccess(LOG_TAG, `Site URL: ${site.defaultUrl}`);
logger.info();
logger.info(
`To deploy to this site, follow the guide at https://firebase.google.com/docs/hosting/multisites.`,
);
return site;
});