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.

emulators.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.doSetup = void 0;
  4. const clc = require("colorette");
  5. const _ = require("lodash");
  6. const utils = require("../../utils");
  7. const prompt_1 = require("../../prompt");
  8. const types_1 = require("../../emulator/types");
  9. const constants_1 = require("../../emulator/constants");
  10. const downloadableEmulators_1 = require("../../emulator/downloadableEmulators");
  11. async function doSetup(setup, config) {
  12. const choices = types_1.ALL_SERVICE_EMULATORS.map((e) => {
  13. return {
  14. value: e,
  15. name: constants_1.Constants.description(e),
  16. checked: config && (config.has(e) || config.has(`emulators.${e}`)),
  17. };
  18. });
  19. const selections = {};
  20. await (0, prompt_1.prompt)(selections, [
  21. {
  22. type: "checkbox",
  23. name: "emulators",
  24. message: "Which Firebase emulators do you want to set up? " +
  25. "Press Space to select emulators, then Enter to confirm your choices.",
  26. choices: choices,
  27. },
  28. ]);
  29. if (!selections.emulators) {
  30. return;
  31. }
  32. setup.config.emulators = setup.config.emulators || {};
  33. for (const selected of selections.emulators) {
  34. setup.config.emulators[selected] = setup.config.emulators[selected] || {};
  35. const currentPort = setup.config.emulators[selected].port;
  36. if (currentPort) {
  37. utils.logBullet(`Port for ${selected} already configured: ${clc.cyan(currentPort)}`);
  38. }
  39. else {
  40. await (0, prompt_1.prompt)(setup.config.emulators[selected], [
  41. {
  42. type: "number",
  43. name: "port",
  44. message: `Which port do you want to use for the ${clc.underline(selected)} emulator?`,
  45. default: constants_1.Constants.getDefaultPort(selected),
  46. },
  47. ]);
  48. }
  49. }
  50. if (selections.emulators.length) {
  51. const uiDesc = constants_1.Constants.description(types_1.Emulators.UI);
  52. if (setup.config.emulators.ui && setup.config.emulators.ui.enabled !== false) {
  53. const currentPort = setup.config.emulators.ui.port || "(automatic)";
  54. utils.logBullet(`${uiDesc} already enabled with port: ${clc.cyan(currentPort)}`);
  55. }
  56. else {
  57. const ui = setup.config.emulators.ui || {};
  58. setup.config.emulators.ui = ui;
  59. await (0, prompt_1.prompt)(ui, [
  60. {
  61. name: "enabled",
  62. type: "confirm",
  63. message: `Would you like to enable the ${uiDesc}?`,
  64. default: true,
  65. },
  66. ]);
  67. if (ui.enabled) {
  68. await (0, prompt_1.prompt)(ui, [
  69. {
  70. type: "input",
  71. name: "port",
  72. message: `Which port do you want to use for the ${clc.underline(uiDesc)} (leave empty to use any available port)?`,
  73. },
  74. ]);
  75. const portNum = Number.parseInt(ui.port);
  76. ui.port = isNaN(portNum) ? undefined : portNum;
  77. }
  78. }
  79. await (0, prompt_1.prompt)(selections, [
  80. {
  81. name: "download",
  82. type: "confirm",
  83. message: "Would you like to download the emulators now?",
  84. default: true,
  85. },
  86. ]);
  87. }
  88. if (setup.config.emulators.singleProjectMode === undefined) {
  89. setup.config.emulators.singleProjectMode = true;
  90. }
  91. if (selections.download) {
  92. for (const selected of selections.emulators) {
  93. if ((0, types_1.isDownloadableEmulator)(selected)) {
  94. await (0, downloadableEmulators_1.downloadIfNecessary)(selected);
  95. }
  96. }
  97. if (_.get(setup, "config.emulators.ui.enabled")) {
  98. (0, downloadableEmulators_1.downloadIfNecessary)(types_1.Emulators.UI);
  99. }
  100. }
  101. }
  102. exports.doSetup = doSetup;