Няма описание
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hosting-channel-open.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const lodash_1 = require("lodash");
  5. const colorette_1 = require("colorette");
  6. const open = require("open");
  7. const command_1 = require("../command");
  8. const error_1 = require("../error");
  9. const api_1 = require("../hosting/api");
  10. const requirePermissions_1 = require("../requirePermissions");
  11. const projectUtils_1 = require("../projectUtils");
  12. const requireConfig_1 = require("../requireConfig");
  13. const utils_1 = require("../utils");
  14. const prompt_1 = require("../prompt");
  15. const requireHostingSite_1 = require("../requireHostingSite");
  16. exports.command = new command_1.Command("hosting:channel:open [channelId]")
  17. .description("opens the URL for a Firebase Hosting channel")
  18. .help("if unable to open the URL in a browser, it will be displayed in the output")
  19. .option("--site <siteId>", "the site to which the channel belongs")
  20. .before(requireConfig_1.requireConfig)
  21. .before(requirePermissions_1.requirePermissions, ["firebasehosting.sites.get"])
  22. .before(requireHostingSite_1.requireHostingSite)
  23. .action(async (channelId, options) => {
  24. const projectId = (0, projectUtils_1.needProjectId)(options);
  25. const siteId = options.site;
  26. if (!channelId) {
  27. if (options.nonInteractive) {
  28. throw new error_1.FirebaseError(`Please provide a channelId.`);
  29. }
  30. const channels = await (0, api_1.listChannels)(projectId, siteId);
  31. (0, lodash_1.sortBy)(channels, ["name"]);
  32. channelId = await (0, prompt_1.promptOnce)({
  33. type: "list",
  34. message: "Which channel would you like to open?",
  35. choices: channels.map((c) => (0, lodash_1.last)(c.name.split("/")) || c.name),
  36. });
  37. }
  38. channelId = (0, api_1.normalizeName)(channelId);
  39. const channel = await (0, api_1.getChannel)(projectId, siteId, channelId);
  40. if (!channel) {
  41. throw new error_1.FirebaseError(`Could not find the channel ${(0, colorette_1.bold)(channelId)} for site ${(0, colorette_1.bold)(siteId)}.`);
  42. }
  43. (0, utils_1.logLabeledBullet)("hosting:channel", channel.url);
  44. if (!options.nonInteractive) {
  45. open(channel.url);
  46. }
  47. return { url: channel.url };
  48. });