UNPKG

firebase-tools

Version:
54 lines (53 loc) 2.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.printBackendsTable = exports.command = void 0; const command_1 = require("../command"); const utils_1 = require("../utils"); const error_1 = require("../error"); const logger_1 = require("../logger"); const projectUtils_1 = require("../projectUtils"); const apphosting = require("../gcp/apphosting"); const Table = require("cli-table3"); const utils_2 = require("../utils"); const TABLE_HEAD = ["Backend", "Repository", "URL", "Location", "Updated Date"]; exports.command = new command_1.Command("apphosting:backends:list") .description("list Firebase App Hosting backends") .option("-l, --location <location>", "list backends in the specified location") .before(apphosting.ensureApiEnabled) .action(async (options) => { var _a, _b; if (options.location !== undefined) { (0, utils_2.logWarning)("--location is being removed in the next major release."); } const projectId = (0, projectUtils_1.needProjectId)(options); const location = (_a = options.location) !== null && _a !== void 0 ? _a : "-"; let backendRes; try { backendRes = await apphosting.listBackends(projectId, location); } catch (err) { throw new error_1.FirebaseError(`Unable to list backends present for project: ${projectId}. Please check the parameters you have provided.`, { original: err }); } const backends = (_b = backendRes.backends) !== null && _b !== void 0 ? _b : []; printBackendsTable(backends); return backends; }); function printBackendsTable(backends) { var _a, _b, _c; const table = new Table({ head: TABLE_HEAD, style: { head: ["green"] }, }); for (const backend of backends) { const { location, id } = apphosting.parseBackendName(backend.name); table.push([ id, (_c = (_b = (_a = backend.codebase) === null || _a === void 0 ? void 0 : _a.repository) === null || _b === void 0 ? void 0 : _b.split("/").pop()) !== null && _c !== void 0 ? _c : "", backend.uri.startsWith("https:") ? backend.uri : "https://" + backend.uri, location, (0, utils_1.datetimeString)(new Date(backend.updateTime)), ]); } logger_1.logger.info(table.toString()); } exports.printBackendsTable = printBackendsTable;