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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const clc = require("colorette");
  5. const ora = require("ora");
  6. const command_1 = require("../command");
  7. const projectUtils_1 = require("../projectUtils");
  8. const error_1 = require("../error");
  9. const apps_1 = require("../management/apps");
  10. const prompt_1 = require("../prompt");
  11. const requireAuth_1 = require("../requireAuth");
  12. const logger_1 = require("../logger");
  13. const DISPLAY_NAME_QUESTION = {
  14. type: "input",
  15. name: "displayName",
  16. default: "",
  17. message: "What would you like to call your app?",
  18. };
  19. function logPostAppCreationInformation(appMetadata, appPlatform) {
  20. logger_1.logger.info("");
  21. logger_1.logger.info(`🎉🎉🎉 Your Firebase ${appPlatform} App is ready! 🎉🎉🎉`);
  22. logger_1.logger.info("");
  23. logger_1.logger.info("App information:");
  24. logger_1.logger.info(` - App ID: ${appMetadata.appId}`);
  25. if (appMetadata.displayName) {
  26. logger_1.logger.info(` - Display name: ${appMetadata.displayName}`);
  27. }
  28. if (appPlatform === apps_1.AppPlatform.IOS) {
  29. const iosAppMetadata = appMetadata;
  30. logger_1.logger.info(` - Bundle ID: ${iosAppMetadata.bundleId}`);
  31. if (iosAppMetadata.appStoreId) {
  32. logger_1.logger.info(` - App Store ID: ${iosAppMetadata.appStoreId}`);
  33. }
  34. }
  35. else if (appPlatform === apps_1.AppPlatform.ANDROID) {
  36. logger_1.logger.info(` - Package name: ${appMetadata.packageName}`);
  37. }
  38. logger_1.logger.info("");
  39. logger_1.logger.info("You can run this command to print out your new app's Google Services config:");
  40. logger_1.logger.info(` firebase apps:sdkconfig ${appPlatform} ${appMetadata.appId}`);
  41. }
  42. async function initiateIosAppCreation(options) {
  43. if (!options.nonInteractive) {
  44. await (0, prompt_1.prompt)(options, [
  45. DISPLAY_NAME_QUESTION,
  46. {
  47. type: "input",
  48. default: "",
  49. name: "bundleId",
  50. message: "Please specify your iOS app bundle ID:",
  51. },
  52. {
  53. type: "input",
  54. default: "",
  55. name: "appStoreId",
  56. message: "Please specify your iOS app App Store ID:",
  57. },
  58. ]);
  59. }
  60. if (!options.bundleId) {
  61. throw new error_1.FirebaseError("Bundle ID for iOS app cannot be empty");
  62. }
  63. const spinner = ora("Creating your iOS app").start();
  64. try {
  65. const appData = await (0, apps_1.createIosApp)(options.project, {
  66. displayName: options.displayName,
  67. bundleId: options.bundleId,
  68. appStoreId: options.appStoreId,
  69. });
  70. spinner.succeed();
  71. return appData;
  72. }
  73. catch (err) {
  74. spinner.fail();
  75. throw err;
  76. }
  77. }
  78. async function initiateAndroidAppCreation(options) {
  79. if (!options.nonInteractive) {
  80. await (0, prompt_1.prompt)(options, [
  81. DISPLAY_NAME_QUESTION,
  82. {
  83. type: "input",
  84. default: "",
  85. name: "packageName",
  86. message: "Please specify your Android app package name:",
  87. },
  88. ]);
  89. }
  90. if (!options.packageName) {
  91. throw new error_1.FirebaseError("Package name for Android app cannot be empty");
  92. }
  93. const spinner = ora("Creating your Android app").start();
  94. try {
  95. const appData = await (0, apps_1.createAndroidApp)(options.project, {
  96. displayName: options.displayName,
  97. packageName: options.packageName,
  98. });
  99. spinner.succeed();
  100. return appData;
  101. }
  102. catch (err) {
  103. spinner.fail();
  104. throw err;
  105. }
  106. }
  107. async function initiateWebAppCreation(options) {
  108. if (!options.nonInteractive) {
  109. await (0, prompt_1.prompt)(options, [DISPLAY_NAME_QUESTION]);
  110. }
  111. if (!options.displayName) {
  112. throw new error_1.FirebaseError("Display name for Web app cannot be empty");
  113. }
  114. const spinner = ora("Creating your Web app").start();
  115. try {
  116. const appData = await (0, apps_1.createWebApp)(options.project, { displayName: options.displayName });
  117. spinner.succeed();
  118. return appData;
  119. }
  120. catch (err) {
  121. spinner.fail();
  122. throw err;
  123. }
  124. }
  125. exports.command = new command_1.Command("apps:create [platform] [displayName]")
  126. .description("create a new Firebase app. [platform] can be IOS, ANDROID or WEB (case insensitive).")
  127. .option("-a, --package-name <packageName>", "required package name for the Android app")
  128. .option("-b, --bundle-id <bundleId>", "required bundle id for the iOS app")
  129. .option("-s, --app-store-id <appStoreId>", "(optional) app store id for the iOS app")
  130. .before(requireAuth_1.requireAuth)
  131. .action(async (platform = "", displayName, options) => {
  132. const projectId = (0, projectUtils_1.needProjectId)(options);
  133. if (!options.nonInteractive && !platform) {
  134. platform = await (0, prompt_1.promptOnce)({
  135. type: "list",
  136. message: "Please choose the platform of the app:",
  137. choices: [
  138. { name: "iOS", value: apps_1.AppPlatform.IOS },
  139. { name: "Android", value: apps_1.AppPlatform.ANDROID },
  140. { name: "Web", value: apps_1.AppPlatform.WEB },
  141. ],
  142. });
  143. }
  144. const appPlatform = (0, apps_1.getAppPlatform)(platform);
  145. if (appPlatform === apps_1.AppPlatform.ANY) {
  146. throw new error_1.FirebaseError("App platform must be provided");
  147. }
  148. logger_1.logger.info(`Create your ${appPlatform} app in project ${clc.bold(projectId)}:`);
  149. options.displayName = displayName;
  150. let appData;
  151. switch (appPlatform) {
  152. case apps_1.AppPlatform.IOS:
  153. appData = await initiateIosAppCreation(options);
  154. break;
  155. case apps_1.AppPlatform.ANDROID:
  156. appData = await initiateAndroidAppCreation(options);
  157. break;
  158. case apps_1.AppPlatform.WEB:
  159. appData = await initiateWebAppCreation(options);
  160. break;
  161. default:
  162. throw new error_1.FirebaseError("Unexpected error. This should not happen");
  163. }
  164. logPostAppCreationInformation(appData, appPlatform);
  165. return appData;
  166. });