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.

deploy.js 3.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.deploy = void 0;
  4. const uploader_1 = require("./uploader");
  5. const detectProjectRoot_1 = require("../../detectProjectRoot");
  6. const listFiles_1 = require("../../listFiles");
  7. const logger_1 = require("../../logger");
  8. const track_1 = require("../../track");
  9. const utils_1 = require("../../utils");
  10. const colorette_1 = require("colorette");
  11. const ora = require("ora");
  12. const fsutils_1 = require("../../fsutils");
  13. const error_1 = require("../../error");
  14. async function deploy(context, options) {
  15. var _a, _b;
  16. if (!((_a = context.hosting) === null || _a === void 0 ? void 0 : _a.deploys)) {
  17. return;
  18. }
  19. const spinner = ora();
  20. function updateSpinner(newMessage, debugging) {
  21. if (debugging) {
  22. (0, utils_1.logLabeledBullet)("hosting", newMessage);
  23. }
  24. else {
  25. spinner.text = `${(0, colorette_1.bold)((0, colorette_1.cyan)(" hosting:"))} ${newMessage}`;
  26. }
  27. }
  28. async function runDeploys(deploys, debugging) {
  29. var _a;
  30. const deploy = deploys.shift();
  31. if (!deploy) {
  32. return;
  33. }
  34. if (!((_a = deploy.config) === null || _a === void 0 ? void 0 : _a.public)) {
  35. (0, utils_1.logLabeledBullet)(`hosting[${deploy.config.site}]`, 'no "public" directory to upload, continuing with release');
  36. return runDeploys(deploys, debugging);
  37. }
  38. (0, utils_1.logLabeledBullet)(`hosting[${deploy.config.site}]`, "beginning deploy...");
  39. const t0 = Date.now();
  40. const publicDir = options.config.path(deploy.config.public);
  41. if (!(0, fsutils_1.dirExistsSync)(`${publicDir}`)) {
  42. throw new error_1.FirebaseError(`Directory '${deploy.config.public}' for Hosting does not exist.`);
  43. }
  44. const files = (0, listFiles_1.listFiles)(publicDir, deploy.config.ignore);
  45. (0, utils_1.logLabeledBullet)(`hosting[${deploy.config.site}]`, `found ${files.length} files in ${(0, colorette_1.bold)(deploy.config.public)}`);
  46. let concurrency = 200;
  47. const envConcurrency = (0, utils_1.envOverride)("FIREBASE_HOSTING_UPLOAD_CONCURRENCY", "");
  48. if (envConcurrency) {
  49. const c = parseInt(envConcurrency, 10);
  50. if (!isNaN(c) && c > 0) {
  51. concurrency = c;
  52. }
  53. }
  54. logger_1.logger.debug(`[hosting] uploading with ${concurrency} concurrency`);
  55. const uploader = new uploader_1.Uploader({
  56. version: deploy.version,
  57. files: files,
  58. public: publicDir,
  59. cwd: options.cwd,
  60. projectRoot: (0, detectProjectRoot_1.detectProjectRoot)(options),
  61. uploadConcurrency: concurrency,
  62. });
  63. const progressInterval = setInterval(() => updateSpinner(uploader.statusMessage(), debugging), debugging ? 2000 : 200);
  64. if (!debugging) {
  65. spinner.start();
  66. }
  67. try {
  68. await uploader.start();
  69. }
  70. catch (err) {
  71. void (0, track_1.track)("Hosting Deploy", "failure");
  72. throw err;
  73. }
  74. finally {
  75. clearInterval(progressInterval);
  76. updateSpinner(uploader.statusMessage(), debugging);
  77. }
  78. if (!debugging) {
  79. spinner.stop();
  80. }
  81. (0, utils_1.logLabeledSuccess)(`hosting[${deploy.config.site}]`, "file upload complete");
  82. const dt = Date.now() - t0;
  83. logger_1.logger.debug(`[hosting] deploy completed after ${dt}ms`);
  84. void (0, track_1.track)("Hosting Deploy", "success", dt);
  85. return runDeploys(deploys, debugging);
  86. }
  87. const debugging = !!(options.debug || options.nonInteractive);
  88. const deploys = [...(((_b = context.hosting) === null || _b === void 0 ? void 0 : _b.deploys) || [])];
  89. return runDeploys(deploys, debugging);
  90. }
  91. exports.deploy = deploy;