firebase-tools
Version:
Command-Line Interface for Firebase
94 lines (93 loc) • 4.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.command = void 0;
const clc = require("colorette");
const command_1 = require("../command");
const projectUtils_1 = require("../projectUtils");
const error_1 = require("../error");
const apps_1 = require("../management/apps");
const requireAuth_1 = require("../requireAuth");
const logger_1 = require("../logger");
const prompt_1 = require("../prompt");
const getDefaultHostingSite_1 = require("../getDefaultHostingSite");
const interactive_1 = require("../hosting/interactive");
const api_1 = require("../hosting/api");
const utils_1 = require("../utils");
function logPostAppCreationInformation(appMetadata, appPlatform) {
logger_1.logger.info("");
logger_1.logger.info(`🎉🎉🎉 Your Firebase ${appPlatform} App is ready! 🎉🎉🎉`);
logger_1.logger.info("");
logger_1.logger.info("App information:");
logger_1.logger.info(` - App ID: ${appMetadata.appId}`);
if (appMetadata.displayName) {
logger_1.logger.info(` - Display name: ${appMetadata.displayName}`);
}
if (appPlatform === apps_1.AppPlatform.IOS) {
const iosAppMetadata = appMetadata;
logger_1.logger.info(` - Bundle ID: ${iosAppMetadata.bundleId}`);
if (iosAppMetadata.appStoreId) {
logger_1.logger.info(` - App Store ID: ${iosAppMetadata.appStoreId}`);
}
}
else if (appPlatform === apps_1.AppPlatform.ANDROID) {
logger_1.logger.info(` - Package name: ${appMetadata.packageName}`);
}
logger_1.logger.info("");
logger_1.logger.info("You can run this command to print out your new app's Google Services config:");
logger_1.logger.info(` firebase apps:sdkconfig ${appPlatform} ${appMetadata.appId}`);
}
exports.command = new command_1.Command("apps:create [platform] [displayName]")
.description("create a new Firebase app. [platform] can be IOS, ANDROID or WEB (case insensitive)")
.option("-a, --package-name <packageName>", "required package name for the Android app")
.option("-b, --bundle-id <bundleId>", "required bundle id for the iOS app")
.option("-s, --app-store-id <appStoreId>", "(optional) app store id for the iOS app")
.before(requireAuth_1.requireAuth)
.action(async (platform = "", displayName, options) => {
const projectId = (0, projectUtils_1.needProjectId)(options);
let chosenPlatform = typeof platform === "string" ? platform : "";
if (!options.nonInteractive && !chosenPlatform) {
chosenPlatform = await (0, prompt_1.select)({
message: "Please choose the platform of the app:",
choices: [
{ name: "iOS", value: apps_1.AppPlatform.IOS },
{ name: "Android", value: apps_1.AppPlatform.ANDROID },
{ name: "Web", value: apps_1.AppPlatform.WEB },
],
});
}
const appPlatform = (0, apps_1.getAppPlatform)(chosenPlatform);
if (appPlatform === apps_1.AppPlatform.ANY) {
throw new error_1.FirebaseError("App platform must be provided");
}
logger_1.logger.info(`Create your ${appPlatform} app in project ${clc.bold(projectId)}:`);
let newSiteId;
if (appPlatform === apps_1.AppPlatform.WEB) {
const existingSite = await (0, getDefaultHostingSite_1.getDefaultHostingSite)({ projectId }).catch((err) => {
if (err !== getDefaultHostingSite_1.errNoDefaultSite) {
throw err;
}
});
if (existingSite) {
logger_1.logger.info(`Firebase Hosting site is present: ${clc.bold(existingSite)}.`);
}
else if (await (0, prompt_1.confirm)({
message: "A Firebase Hosting site is recommended for Web apps. Would you like to create a default site now?",
default: true,
nonInteractive: options.nonInteractive,
})) {
newSiteId = await (0, interactive_1.pickHostingSiteName)("", {
projectId,
nonInteractive: options.nonInteractive,
});
}
}
options.displayName = displayName;
const appData = await (0, apps_1.sdkInit)(appPlatform, options);
if (newSiteId) {
await (0, api_1.createSite)(projectId, newSiteId, appData.appId);
logger_1.logger.info("");
(0, utils_1.logSuccess)(`Firebase Hosting site ${newSiteId} created!`);
}
logPostAppCreationInformation(appData, appPlatform);
return appData;
});