Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const ora = require("ora");
  5. const fs = require("fs-extra");
  6. const command_1 = require("../command");
  7. const apps_1 = require("../management/apps");
  8. const projectUtils_1 = require("../projectUtils");
  9. const projects_1 = require("../management/projects");
  10. const error_1 = require("../error");
  11. const requireAuth_1 = require("../requireAuth");
  12. const logger_1 = require("../logger");
  13. const prompt_1 = require("../prompt");
  14. function checkForApps(apps, appPlatform) {
  15. if (!apps.length) {
  16. throw new error_1.FirebaseError(`There are no ${appPlatform === apps_1.AppPlatform.ANY ? "" : appPlatform + " "}apps ` +
  17. "associated with this Firebase project");
  18. }
  19. }
  20. async function selectAppInteractively(apps, appPlatform) {
  21. checkForApps(apps, appPlatform);
  22. const choices = apps.map((app) => {
  23. return {
  24. name: `${app.displayName || app.bundleId || app.packageName}` +
  25. ` - ${app.appId} (${app.platform})`,
  26. value: app,
  27. };
  28. });
  29. return await (0, prompt_1.promptOnce)({
  30. type: "list",
  31. message: `Select the ${appPlatform === apps_1.AppPlatform.ANY ? "" : appPlatform + " "}` +
  32. "app to get the configuration data:",
  33. choices,
  34. });
  35. }
  36. exports.command = new command_1.Command("apps:sdkconfig [platform] [appId]")
  37. .description("print the Google Services config of a Firebase app. " +
  38. "[platform] can be IOS, ANDROID or WEB (case insensitive)")
  39. .option("-o, --out [file]", "(optional) write config output to a file")
  40. .before(requireAuth_1.requireAuth)
  41. .action(async (platform = "", appId = "", options) => {
  42. let appPlatform = (0, apps_1.getAppPlatform)(platform);
  43. if (!appId) {
  44. let projectId = (0, projectUtils_1.needProjectId)(options);
  45. if (options.nonInteractive && !projectId) {
  46. throw new error_1.FirebaseError("Must supply app and project ids in non-interactive mode.");
  47. }
  48. else if (!projectId) {
  49. const result = await (0, projects_1.getOrPromptProject)(options);
  50. projectId = result.projectId;
  51. }
  52. const apps = await (0, apps_1.listFirebaseApps)(projectId, appPlatform);
  53. checkForApps(apps, appPlatform);
  54. if (apps.length === 1) {
  55. appId = apps[0].appId;
  56. appPlatform = apps[0].platform;
  57. }
  58. else if (options.nonInteractive) {
  59. throw new error_1.FirebaseError(`Project ${projectId} has multiple apps, must specify an app id.`);
  60. }
  61. else {
  62. const appMetadata = await selectAppInteractively(apps, appPlatform);
  63. appId = appMetadata.appId;
  64. appPlatform = appMetadata.platform;
  65. }
  66. }
  67. let configData;
  68. const spinner = ora(`Downloading configuration data of your Firebase ${appPlatform} app`).start();
  69. try {
  70. configData = await (0, apps_1.getAppConfig)(appId, appPlatform);
  71. }
  72. catch (err) {
  73. spinner.fail();
  74. throw err;
  75. }
  76. spinner.succeed();
  77. const fileInfo = (0, apps_1.getAppConfigFile)(configData, appPlatform);
  78. if (appPlatform === apps_1.AppPlatform.WEB) {
  79. fileInfo.sdkConfig = configData;
  80. }
  81. if (options.out === undefined) {
  82. logger_1.logger.info(fileInfo.fileContents);
  83. return fileInfo;
  84. }
  85. const shouldUseDefaultFilename = options.out === true || options.out === "";
  86. const filename = shouldUseDefaultFilename ? configData.fileName : options.out;
  87. if (fs.existsSync(filename)) {
  88. if (options.nonInteractive) {
  89. throw new error_1.FirebaseError(`${filename} already exists`);
  90. }
  91. const overwrite = await (0, prompt_1.promptOnce)({
  92. type: "confirm",
  93. default: false,
  94. message: `${filename} already exists. Do you want to overwrite?`,
  95. });
  96. if (!overwrite) {
  97. return configData;
  98. }
  99. }
  100. fs.writeFileSync(filename, fileInfo.fileContents);
  101. logger_1.logger.info(`App configuration is written in ${filename}`);
  102. return configData;
  103. });