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-start.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const command_1 = require("../command");
  5. const controller = require("../emulator/controller");
  6. const commandUtils = require("../emulator/commandUtils");
  7. const logger_1 = require("../logger");
  8. const registry_1 = require("../emulator/registry");
  9. const types_1 = require("../emulator/types");
  10. const clc = require("colorette");
  11. const constants_1 = require("../emulator/constants");
  12. const utils_1 = require("../utils");
  13. const Table = require("cli-table");
  14. function stylizeLink(url) {
  15. return clc.underline(clc.bold(url));
  16. }
  17. exports.command = new command_1.Command("emulators:start")
  18. .before(commandUtils.setExportOnExitOptions)
  19. .before(commandUtils.beforeEmulatorCommand)
  20. .description("start the local Firebase emulators")
  21. .option(commandUtils.FLAG_ONLY, commandUtils.DESC_ONLY)
  22. .option(commandUtils.FLAG_INSPECT_FUNCTIONS, commandUtils.DESC_INSPECT_FUNCTIONS)
  23. .option(commandUtils.FLAG_IMPORT, commandUtils.DESC_IMPORT)
  24. .option(commandUtils.FLAG_EXPORT_ON_EXIT, commandUtils.DESC_EXPORT_ON_EXIT)
  25. .action((options) => {
  26. const killSignalPromise = commandUtils.shutdownWhenKilled(options);
  27. return Promise.race([
  28. killSignalPromise,
  29. (async () => {
  30. let deprecationNotices;
  31. try {
  32. ({ deprecationNotices } = await controller.startAll(options));
  33. }
  34. catch (e) {
  35. await controller.cleanShutdown();
  36. throw e;
  37. }
  38. printEmulatorOverview(options);
  39. for (const notice of deprecationNotices) {
  40. (0, utils_1.logLabeledWarning)("emulators", notice, "warn");
  41. }
  42. return killSignalPromise;
  43. })(),
  44. ]);
  45. });
  46. function printEmulatorOverview(options) {
  47. const reservedPorts = [];
  48. for (const internalEmulator of [types_1.Emulators.LOGGING]) {
  49. const info = registry_1.EmulatorRegistry.getInfo(internalEmulator);
  50. if (info) {
  51. reservedPorts.push(info.port);
  52. }
  53. controller.filterEmulatorTargets(options).forEach((emulator) => {
  54. var _a;
  55. reservedPorts.push(...(((_a = registry_1.EmulatorRegistry.getInfo(emulator)) === null || _a === void 0 ? void 0 : _a.reservedPorts) || []));
  56. });
  57. }
  58. const reservedPortsString = reservedPorts.length > 0 ? reservedPorts.join(", ") : "None";
  59. const uiRunning = registry_1.EmulatorRegistry.isRunning(types_1.Emulators.UI);
  60. const head = ["Emulator", "Host:Port"];
  61. if (uiRunning) {
  62. head.push(`View in ${constants_1.Constants.description(types_1.Emulators.UI)}`);
  63. }
  64. const successMessageTable = new Table();
  65. let successMsg = `${clc.green("✔")} ${clc.bold("All emulators ready! It is now safe to connect your app.")}`;
  66. if (uiRunning) {
  67. successMsg += `\n${clc.cyan("i")} View Emulator UI at ${stylizeLink(registry_1.EmulatorRegistry.url(types_1.Emulators.UI).toString())}`;
  68. }
  69. successMessageTable.push([successMsg]);
  70. const emulatorsTable = new Table({
  71. head: head,
  72. style: {
  73. head: ["yellow"],
  74. },
  75. });
  76. emulatorsTable.push(...controller
  77. .filterEmulatorTargets(options)
  78. .map((emulator) => {
  79. const emulatorName = constants_1.Constants.description(emulator).replace(/ emulator/i, "");
  80. const isSupportedByUi = types_1.EMULATORS_SUPPORTED_BY_UI.includes(emulator);
  81. const listen = commandUtils.getListenOverview(emulator);
  82. if (!listen) {
  83. const row = [emulatorName, "Failed to initialize (see above)"];
  84. if (uiRunning) {
  85. row.push("");
  86. }
  87. return row;
  88. }
  89. let uiLink = "n/a";
  90. if (isSupportedByUi && uiRunning) {
  91. const url = registry_1.EmulatorRegistry.url(types_1.Emulators.UI);
  92. url.pathname = `/${emulator}`;
  93. uiLink = stylizeLink(url.toString());
  94. }
  95. return [emulatorName, listen, uiLink];
  96. })
  97. .map((col) => col.slice(0, head.length))
  98. .filter((v) => v));
  99. let extensionsTable = "";
  100. if (registry_1.EmulatorRegistry.isRunning(types_1.Emulators.EXTENSIONS)) {
  101. const extensionsEmulatorInstance = registry_1.EmulatorRegistry.get(types_1.Emulators.EXTENSIONS);
  102. extensionsTable = extensionsEmulatorInstance.extensionsInfoTable(options);
  103. }
  104. logger_1.logger.info(`\n${successMessageTable}
  105. ${emulatorsTable}
  106. ${registry_1.EmulatorRegistry.isRunning(types_1.Emulators.HUB)
  107. ? clc.blackBright(" Emulator Hub running at ") + registry_1.EmulatorRegistry.url(types_1.Emulators.HUB).host
  108. : clc.blackBright(" Emulator Hub not running.")}
  109. ${clc.blackBright(" Other reserved ports:")} ${reservedPortsString}
  110. ${extensionsTable}
  111. Issues? Report them at ${stylizeLink("https://github.com/firebase/firebase-tools/issues")} and attach the *-debug.log files.
  112. `);
  113. }