No Description
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-create.js 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const colorette_1 = require("colorette");
  5. const api_1 = require("../hosting/api");
  6. const command_1 = require("../command");
  7. const expireUtils_1 = require("../hosting/expireUtils");
  8. const error_1 = require("../error");
  9. const utils_1 = require("../utils");
  10. const prompt_1 = require("../prompt");
  11. const requirePermissions_1 = require("../requirePermissions");
  12. const projectUtils_1 = require("../projectUtils");
  13. const logger_1 = require("../logger");
  14. const requireConfig_1 = require("../requireConfig");
  15. const { marked } = require("marked");
  16. const requireHostingSite_1 = require("../requireHostingSite");
  17. const LOG_TAG = "hosting:channel";
  18. exports.command = new command_1.Command("hosting:channel:create [channelId]")
  19. .description("create a Firebase Hosting channel")
  20. .option("-e, --expires <duration>", "duration string (e.g. 12h or 30d) for channel expiration, max 30d")
  21. .option("--site <siteId>", "site for which to create the channel")
  22. .before(requireConfig_1.requireConfig)
  23. .before(requirePermissions_1.requirePermissions, ["firebasehosting.sites.update"])
  24. .before(requireHostingSite_1.requireHostingSite)
  25. .action(async (channelId, options) => {
  26. const projectId = (0, projectUtils_1.needProjectId)(options);
  27. const site = options.site;
  28. let expireTTL = expireUtils_1.DEFAULT_DURATION;
  29. if (options.expires) {
  30. expireTTL = (0, expireUtils_1.calculateChannelExpireTTL)(options.expires);
  31. }
  32. if (channelId) {
  33. options.channelId = channelId;
  34. }
  35. channelId =
  36. channelId ||
  37. (await (0, prompt_1.promptOnce)({
  38. type: "input",
  39. message: "Please provide a URL-friendly name for the channel:",
  40. validate: (s) => s.length > 0,
  41. }));
  42. channelId = (0, api_1.normalizeName)(channelId);
  43. let channel;
  44. try {
  45. channel = await (0, api_1.createChannel)(projectId, site, channelId, expireTTL);
  46. }
  47. catch (e) {
  48. if (e.status === 409) {
  49. throw new error_1.FirebaseError(`Channel ${(0, colorette_1.bold)(channelId)} already exists on site ${(0, colorette_1.bold)(site)}. Deploy to ${(0, colorette_1.bold)(channelId)} with: ${(0, colorette_1.yellow)(`firebase hosting:channel:deploy ${channelId}`)}`, { original: e });
  50. }
  51. throw e;
  52. }
  53. try {
  54. await (0, api_1.addAuthDomains)(projectId, [channel.url]);
  55. }
  56. catch (e) {
  57. (0, utils_1.logLabeledWarning)(LOG_TAG, marked(`Unable to add channel domain to Firebase Auth. Visit the Firebase Console at ${(0, utils_1.consoleUrl)(projectId, "/authentication/providers")}`));
  58. logger_1.logger.debug("[hosting] unable to add auth domain", e);
  59. }
  60. logger_1.logger.info();
  61. (0, utils_1.logLabeledSuccess)(LOG_TAG, `Channel ${(0, colorette_1.bold)(channelId)} has been created on site ${(0, colorette_1.bold)(site)}.`);
  62. (0, utils_1.logLabeledSuccess)(LOG_TAG, `Channel ${(0, colorette_1.bold)(channelId)} will expire at ${(0, colorette_1.bold)((0, utils_1.datetimeString)(new Date(channel.expireTime)))}.`);
  63. (0, utils_1.logLabeledSuccess)(LOG_TAG, `Channel URL: ${channel.url}`);
  64. logger_1.logger.info();
  65. logger_1.logger.info(`To deploy to this channel, use ${(0, colorette_1.yellow)(`firebase hosting:channel:deploy ${channelId}`)}.`);
  66. return channel;
  67. });