Нема описа
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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.implicitInit = void 0;
  4. const _ = require("lodash");
  5. const clc = require("colorette");
  6. const fs = require("fs");
  7. const fetchWebSetup_1 = require("../fetchWebSetup");
  8. const utils = require("../utils");
  9. const logger_1 = require("../logger");
  10. const registry_1 = require("../emulator/registry");
  11. const types_1 = require("../emulator/types");
  12. const INIT_TEMPLATE = fs.readFileSync(__dirname + "/../../templates/hosting/init.js", "utf8");
  13. async function implicitInit(options) {
  14. let config;
  15. try {
  16. config = await (0, fetchWebSetup_1.fetchWebSetup)(options);
  17. }
  18. catch (e) {
  19. logger_1.logger.debug("fetchWebSetup error: " + e);
  20. const statusCode = _.get(e, "context.response.statusCode");
  21. if (statusCode === 403) {
  22. utils.logLabeledWarning("hosting", `Authentication error when trying to fetch your current web app configuration, have you run ${clc.bold("firebase login")}?`);
  23. }
  24. }
  25. if (!config) {
  26. config = (0, fetchWebSetup_1.getCachedWebSetup)(options);
  27. if (config) {
  28. utils.logLabeledWarning("hosting", "Using web app configuration from cache.");
  29. }
  30. }
  31. if (!config) {
  32. config = undefined;
  33. utils.logLabeledWarning("hosting", "Could not fetch web app configuration and there is no cached configuration on this machine. " +
  34. "Check your internet connection and make sure you are authenticated. " +
  35. "To continue, you must call firebase.initializeApp({...}) in your code before using Firebase.");
  36. }
  37. const configJson = JSON.stringify(config, null, 2);
  38. const emulators = {};
  39. for (const e of types_1.EMULATORS_SUPPORTED_BY_USE_EMULATOR) {
  40. const info = registry_1.EmulatorRegistry.getInfo(e);
  41. if (info) {
  42. emulators[e] = {
  43. host: info.host,
  44. port: info.port,
  45. hostAndPort: registry_1.EmulatorRegistry.url(e).host,
  46. };
  47. }
  48. }
  49. const emulatorsJson = JSON.stringify(emulators, null, 2);
  50. const js = INIT_TEMPLATE.replace("/*--CONFIG--*/", `var firebaseConfig = ${configJson};`).replace("/*--EMULATORS--*/", "var firebaseEmulators = undefined;");
  51. const emulatorsJs = INIT_TEMPLATE.replace("/*--CONFIG--*/", `var firebaseConfig = ${configJson};`).replace("/*--EMULATORS--*/", `var firebaseEmulators = ${emulatorsJson};`);
  52. return {
  53. js,
  54. emulatorsJs,
  55. json: configJson,
  56. };
  57. }
  58. exports.implicitInit = implicitInit;