Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

projects-list.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const clc = require("colorette");
  5. const ora = require("ora");
  6. const Table = require("cli-table");
  7. const command_1 = require("../command");
  8. const projects_1 = require("../management/projects");
  9. const requireAuth_1 = require("../requireAuth");
  10. const logger_1 = require("../logger");
  11. const NOT_SPECIFIED = clc.yellow("[Not specified]");
  12. function logProjectsList(projects, currentProjectId) {
  13. if (!projects.length) {
  14. return;
  15. }
  16. const tableHead = [
  17. "Project Display Name",
  18. "Project ID",
  19. "Project Number",
  20. "Resource Location ID",
  21. ];
  22. const table = new Table({ head: tableHead, style: { head: ["green"] } });
  23. projects.forEach(({ projectId, projectNumber, displayName, resources }) => {
  24. if (projectId === currentProjectId) {
  25. projectId = clc.cyan(clc.bold(`${projectId} (current)`));
  26. }
  27. table.push([
  28. displayName || NOT_SPECIFIED,
  29. projectId,
  30. projectNumber,
  31. (resources && resources.locationId) || NOT_SPECIFIED,
  32. ]);
  33. });
  34. logger_1.logger.info(table.toString());
  35. }
  36. function logProjectCount(arr = []) {
  37. if (!arr.length) {
  38. logger_1.logger.info(clc.bold("No projects found."));
  39. return;
  40. }
  41. logger_1.logger.info("");
  42. logger_1.logger.info(`${arr.length} project(s) total.`);
  43. }
  44. exports.command = new command_1.Command("projects:list")
  45. .description("list all Firebase projects you have access to")
  46. .before(requireAuth_1.requireAuth)
  47. .action(async (options) => {
  48. const spinner = ora("Preparing the list of your Firebase projects").start();
  49. let projects;
  50. try {
  51. projects = await (0, projects_1.listFirebaseProjects)();
  52. }
  53. catch (err) {
  54. spinner.fail();
  55. throw err;
  56. }
  57. spinner.succeed();
  58. logProjectsList(projects, options.project);
  59. logProjectCount(projects);
  60. return projects;
  61. });