GSI - Employe Self Service Mobile
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.

104 lines
4.9 KiB

2 months ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.deploy = void 0;
  4. const logger_1 = require("../logger");
  5. const api_1 = require("../api");
  6. const colorette_1 = require("colorette");
  7. const lodash_1 = require("lodash");
  8. const projectUtils_1 = require("../projectUtils");
  9. const utils_1 = require("../utils");
  10. const error_1 = require("../error");
  11. const track_1 = require("../track");
  12. const lifecycleHooks_1 = require("./lifecycleHooks");
  13. const experiments = require("../experiments");
  14. const HostingTarget = require("./hosting");
  15. const DatabaseTarget = require("./database");
  16. const FirestoreTarget = require("./firestore");
  17. const FunctionsTarget = require("./functions");
  18. const StorageTarget = require("./storage");
  19. const RemoteConfigTarget = require("./remoteconfig");
  20. const ExtensionsTarget = require("./extensions");
  21. const frameworks_1 = require("../frameworks");
  22. const requirePermissions_1 = require("../requirePermissions");
  23. const deploy_1 = require("../commands/deploy");
  24. const TARGETS = {
  25. hosting: HostingTarget,
  26. database: DatabaseTarget,
  27. firestore: FirestoreTarget,
  28. functions: FunctionsTarget,
  29. storage: StorageTarget,
  30. remoteconfig: RemoteConfigTarget,
  31. extensions: ExtensionsTarget,
  32. };
  33. const chain = async function (fns, context, options, payload) {
  34. for (const latest of fns) {
  35. await latest(context, options, payload);
  36. }
  37. };
  38. const deploy = async function (targetNames, options, customContext = {}) {
  39. const projectId = (0, projectUtils_1.needProjectId)(options);
  40. const payload = {};
  41. const context = Object.assign({ projectId }, customContext);
  42. const predeploys = [];
  43. const prepares = [];
  44. const deploys = [];
  45. const releases = [];
  46. const postdeploys = [];
  47. const startTime = Date.now();
  48. if (targetNames.includes("hosting")) {
  49. const config = options.config.get("hosting");
  50. if (Array.isArray(config) ? config.some((it) => it.source) : config.source) {
  51. experiments.assertEnabled("webframeworks", "deploy a web framework to hosting");
  52. const usedToTargetFunctions = targetNames.includes("functions");
  53. await (0, frameworks_1.prepareFrameworks)(targetNames, context, options);
  54. const nowTargetsFunctions = targetNames.includes("functions");
  55. if (nowTargetsFunctions && !usedToTargetFunctions) {
  56. if (context.hostingChannel && !experiments.isEnabled("pintags")) {
  57. throw new error_1.FirebaseError("Web frameworks with dynamic content do not yet support deploying to preview channels");
  58. }
  59. await (0, requirePermissions_1.requirePermissions)(deploy_1.TARGET_PERMISSIONS["functions"]);
  60. }
  61. }
  62. }
  63. for (const targetName of targetNames) {
  64. const target = TARGETS[targetName];
  65. if (!target) {
  66. return Promise.reject(new error_1.FirebaseError(`${(0, colorette_1.bold)(targetName)} is not a valid deploy target`));
  67. }
  68. predeploys.push((0, lifecycleHooks_1.lifecycleHooks)(targetName, "predeploy"));
  69. prepares.push(target.prepare);
  70. deploys.push(target.deploy);
  71. releases.push(target.release);
  72. postdeploys.push((0, lifecycleHooks_1.lifecycleHooks)(targetName, "postdeploy"));
  73. }
  74. logger_1.logger.info();
  75. logger_1.logger.info((0, colorette_1.bold)((0, colorette_1.white)("===") + " Deploying to '" + projectId + "'..."));
  76. logger_1.logger.info();
  77. (0, utils_1.logBullet)("deploying " + (0, colorette_1.bold)(targetNames.join(", ")));
  78. await chain(predeploys, context, options, payload);
  79. await chain(prepares, context, options, payload);
  80. await chain(deploys, context, options, payload);
  81. await chain(releases, context, options, payload);
  82. await chain(postdeploys, context, options, payload);
  83. if ((0, lodash_1.has)(options, "config.notes.databaseRules")) {
  84. await (0, track_1.track)("Rules Deploy", options.config.notes.databaseRules);
  85. }
  86. const duration = Date.now() - startTime;
  87. await (0, track_1.track)("Product Deploy", [...targetNames].sort().join(","), duration);
  88. logger_1.logger.info();
  89. (0, utils_1.logSuccess)((0, colorette_1.bold)((0, colorette_1.underline)("Deploy complete!")));
  90. logger_1.logger.info();
  91. const deployedHosting = (0, lodash_1.includes)(targetNames, "hosting");
  92. logger_1.logger.info((0, colorette_1.bold)("Project Console:"), (0, utils_1.consoleUrl)(options.project, "/overview"));
  93. if (deployedHosting) {
  94. (0, lodash_1.each)(context.hosting.deploys, (deploy) => {
  95. logger_1.logger.info((0, colorette_1.bold)("Hosting URL:"), (0, utils_1.addSubdomain)(api_1.hostingOrigin, deploy.config.site));
  96. });
  97. const versionNames = context.hosting.deploys.map((deploy) => deploy.version);
  98. return { hosting: versionNames.length === 1 ? versionNames[0] : versionNames };
  99. }
  100. else {
  101. return { hosting: undefined };
  102. }
  103. };
  104. exports.deploy = deploy;