Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const clc = require("colorette");
  5. const { marked } = require("marked");
  6. const TerminalRenderer = require("marked-terminal");
  7. const displayExtensionInfo_1 = require("../extensions/displayExtensionInfo");
  8. const askUserForEventsConfig = require("../extensions/askUserForEventsConfig");
  9. const checkMinRequiredVersion_1 = require("../checkMinRequiredVersion");
  10. const command_1 = require("../command");
  11. const error_1 = require("../error");
  12. const projectUtils_1 = require("../projectUtils");
  13. const extensionsApi = require("../extensions/extensionsApi");
  14. const refs = require("../extensions/refs");
  15. const warnings_1 = require("../extensions/warnings");
  16. const paramHelper = require("../extensions/paramHelper");
  17. const extensionsHelper_1 = require("../extensions/extensionsHelper");
  18. const utils_1 = require("../extensions/utils");
  19. const requirePermissions_1 = require("../requirePermissions");
  20. const utils = require("../utils");
  21. const track_1 = require("../track");
  22. const experiments = require("../experiments");
  23. const manifest = require("../extensions/manifest");
  24. marked.setOptions({
  25. renderer: new TerminalRenderer(),
  26. });
  27. exports.command = new command_1.Command("ext:install [extensionName]")
  28. .description("install an official extension if [extensionName] or [extensionName@version] is provided; " +
  29. (experiments.isEnabled("extdev")
  30. ? "install a local extension if [localPathOrUrl] or [url#root] is provided; install a published extension (not authored by Firebase) if [publisherId/extensionId] is provided "
  31. : "") +
  32. "or run with `-i` to see all available extensions.")
  33. .option("--local", "deprecated")
  34. .withForce()
  35. .before(requirePermissions_1.requirePermissions, ["firebaseextensions.instances.create"])
  36. .before(extensionsHelper_1.ensureExtensionsApiEnabled)
  37. .before(checkMinRequiredVersion_1.checkMinRequiredVersion, "extMinVersion")
  38. .before(extensionsHelper_1.diagnoseAndFixProject)
  39. .action(async (extensionName, options) => {
  40. var _a;
  41. const projectId = (0, projectUtils_1.getProjectId)(options);
  42. const paramsEnvPath = "";
  43. let learnMore = false;
  44. if (!extensionName) {
  45. if (options.interactive) {
  46. learnMore = true;
  47. extensionName = await (0, extensionsHelper_1.promptForOfficialExtension)("Which official extension do you wish to install?\n" +
  48. " Select an extension, then press Enter to learn more.");
  49. }
  50. else {
  51. throw new error_1.FirebaseError(`Unable to find published extension '${clc.bold(extensionName)}'. ` +
  52. `Run ${clc.bold("firebase ext:install -i")} to select from the list of all available published extensions.`);
  53. }
  54. }
  55. let source;
  56. let extensionVersion;
  57. if ((0, extensionsHelper_1.isUrlPath)(extensionName)) {
  58. throw new error_1.FirebaseError(`Installing with a source url is no longer supported in the CLI. Please use Firebase Console instead.`);
  59. }
  60. if (options.local) {
  61. utils.logLabeledWarning(extensionsHelper_1.logPrefix, "As of firebase-tools@11.0.0, the `--local` flag is no longer required, as it is the default behavior.");
  62. }
  63. if ((0, extensionsHelper_1.isLocalPath)(extensionName)) {
  64. source = await (0, extensionsHelper_1.createSourceFromLocation)((0, projectUtils_1.needProjectId)({ projectId }), extensionName);
  65. await (0, displayExtensionInfo_1.displayExtInfo)(extensionName, "", source.spec);
  66. void (0, track_1.track)("Extension Install", "Install by Source", options.interactive ? 1 : 0);
  67. }
  68. else {
  69. void (0, track_1.track)("Extension Install", "Install by Extension Ref", options.interactive ? 1 : 0);
  70. extensionName = await (0, extensionsHelper_1.canonicalizeRefInput)(extensionName);
  71. extensionVersion = await extensionsApi.getExtensionVersion(extensionName);
  72. await infoExtensionVersion({
  73. extensionName,
  74. extensionVersion,
  75. });
  76. }
  77. if (!(await (0, extensionsHelper_1.confirm)({
  78. nonInteractive: options.nonInteractive,
  79. force: options.force,
  80. default: true,
  81. }))) {
  82. return;
  83. }
  84. if (!source && !extensionVersion) {
  85. throw new error_1.FirebaseError("Could not find a source. Please specify a valid source to continue.");
  86. }
  87. const spec = (_a = source === null || source === void 0 ? void 0 : source.spec) !== null && _a !== void 0 ? _a : extensionVersion === null || extensionVersion === void 0 ? void 0 : extensionVersion.spec;
  88. if (!spec) {
  89. throw new error_1.FirebaseError(`Could not find the extension.yaml for extension '${clc.bold(extensionName)}'. Please make sure this is a valid extension and try again.`);
  90. }
  91. if (learnMore) {
  92. utils.logLabeledBullet(extensionsHelper_1.logPrefix, `You selected: ${clc.bold(spec.displayName || "")}.\n` +
  93. `${spec.description}\n` +
  94. `View details: https://firebase.google.com/products/extensions/${spec.name}\n`);
  95. }
  96. try {
  97. return installToManifest({
  98. paramsEnvPath,
  99. projectId,
  100. extensionName,
  101. source,
  102. extVersion: extensionVersion,
  103. nonInteractive: options.nonInteractive,
  104. force: options.force,
  105. });
  106. }
  107. catch (err) {
  108. if (!(err instanceof error_1.FirebaseError)) {
  109. throw new error_1.FirebaseError(`Error occurred saving the extension to manifest: ${err.message}`, {
  110. original: err,
  111. });
  112. }
  113. throw err;
  114. }
  115. });
  116. async function infoExtensionVersion(args) {
  117. const ref = refs.parse(args.extensionName);
  118. const extension = await extensionsApi.getExtension(refs.toExtensionRef(ref));
  119. await (0, displayExtensionInfo_1.displayExtInfo)(args.extensionName, ref.publisherId, args.extensionVersion.spec, true);
  120. await (0, warnings_1.displayWarningPrompts)(ref.publisherId, extension.registryLaunchStage, args.extensionVersion);
  121. }
  122. async function installToManifest(options) {
  123. var _a, _b;
  124. const { projectId, extensionName, extVersion, source, paramsEnvPath, nonInteractive, force } = options;
  125. const isLocalSource = (0, extensionsHelper_1.isLocalPath)(extensionName);
  126. const spec = (_a = extVersion === null || extVersion === void 0 ? void 0 : extVersion.spec) !== null && _a !== void 0 ? _a : source === null || source === void 0 ? void 0 : source.spec;
  127. if (!spec) {
  128. throw new error_1.FirebaseError(`Could not find the extension.yaml for ${extensionName}. Please make sure this is a valid extension and try again.`);
  129. }
  130. const config = manifest.loadConfig(options);
  131. let instanceId = spec.name;
  132. while (manifest.instanceExists(instanceId, config)) {
  133. instanceId = await (0, extensionsHelper_1.promptForValidInstanceId)(`${spec.name}-${(0, utils_1.getRandomString)(4)}`);
  134. }
  135. const paramBindingOptions = await paramHelper.getParams({
  136. projectId,
  137. paramSpecs: spec.params.concat((_b = spec.systemParams) !== null && _b !== void 0 ? _b : []),
  138. nonInteractive,
  139. paramsEnvPath,
  140. instanceId,
  141. });
  142. const eventsConfig = spec.events
  143. ? await askUserForEventsConfig.askForEventsConfig(spec.events, "${param:PROJECT_ID}", instanceId)
  144. : undefined;
  145. if (eventsConfig) {
  146. paramBindingOptions.EVENTARC_CHANNEL = { baseValue: eventsConfig.channel };
  147. paramBindingOptions.ALLOWED_EVENT_TYPES = {
  148. baseValue: eventsConfig.allowedEventTypes.join(","),
  149. };
  150. }
  151. const ref = extVersion ? refs.parse(extVersion.ref) : undefined;
  152. await manifest.writeToManifest([
  153. {
  154. instanceId,
  155. ref: !isLocalSource ? ref : undefined,
  156. localPath: isLocalSource ? extensionName : undefined,
  157. params: paramBindingOptions,
  158. extensionSpec: spec,
  159. },
  160. ], config, { nonInteractive, force: force !== null && force !== void 0 ? force : false });
  161. manifest.showPostDeprecationNotice();
  162. }