UNPKG

firebase-tools

Version:
51 lines (50 loc) • 2.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.updateService = updateService; const clc = require("colorette"); const __1 = require(".."); const error_1 = require("../../error"); const projectUtils_1 = require("../../projectUtils"); const util_1 = require("./util"); async function updateService(serviceId, region, options) { const settings = { baseImage: readFlagPair(options.baseImage, options.clearBaseImage, "base-image"), }; if (Object.values(settings).every((value) => value === undefined)) { throw new error_1.FirebaseError("Specify a setting to update: --base-image <baseImage> or --clear-base-image."); } const projectId = (0, projectUtils_1.needProjectId)(options); const config = findServiceToUpdate(serviceId, region, options); if (settings.baseImage === null && config.localBuild) { throw new error_1.FirebaseError(`Cannot clear the base image of ${config.serviceId}: local builds need one.`); } if (!(await (0, util_1.getExistingService)(projectId, config.region, config.serviceId))) { const howToCreate = config.localBuild ? clc.bold("firebase init run") : `${clc.bold("firebase init run")} or ` + clc.bold(`firebase deploy --only run:${(0, util_1.fullServiceName)(config)}`); throw new error_1.FirebaseError(`Cloud Run service ${config.serviceId} doesn't exist in ${config.region} yet. ` + `Create it with ${howToCreate}, then update it.`); } await (0, __1.deploy)(["run"], { ...options, only: `run:${(0, util_1.fullServiceName)(config)}` }, settings); } function readFlagPair(value, clear, flag) { if (value && clear) { throw new error_1.FirebaseError(`Use either --${flag} or --clear-${flag}, not both.`); } return clear ? null : value; } function findServiceToUpdate(serviceId, region, options) { const matches = (0, util_1.getAllServiceConfigs)(options).filter((c) => c.serviceId === serviceId && (!region || c.region === region)); if (!matches.length) { const service = region ? `${serviceId} in ${region}` : serviceId; throw new error_1.FirebaseError(`Cloud Run service ${service} not detected in firebase.json.`); } if (matches.length > 1) { const regions = matches.map((c) => c.region); const example = `firebase run:services:update ${serviceId} --region ${regions[0]}`; throw new error_1.FirebaseError(`firebase.json lists ${serviceId} in ${regions.length} regions: ${regions.join(", ")}. ` + `Pick one with --region, e.g. ${example}`); } return matches[0]; }