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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const { marked } = require("marked");
  5. const TerminalRenderer = require("marked-terminal");
  6. const checkMinRequiredVersion_1 = require("../checkMinRequiredVersion");
  7. const command_1 = require("../command");
  8. const error_1 = require("../error");
  9. const projectUtils_1 = require("../projectUtils");
  10. const extensionsApi = require("../extensions/extensionsApi");
  11. const extensionsHelper_1 = require("../extensions/extensionsHelper");
  12. const paramHelper = require("../extensions/paramHelper");
  13. const requirePermissions_1 = require("../requirePermissions");
  14. const utils = require("../utils");
  15. const logger_1 = require("../logger");
  16. const refs = require("../extensions/refs");
  17. const manifest = require("../extensions/manifest");
  18. const functional_1 = require("../functional");
  19. const paramHelper_1 = require("../extensions/paramHelper");
  20. const askUserForEventsConfig = require("../extensions/askUserForEventsConfig");
  21. marked.setOptions({
  22. renderer: new TerminalRenderer(),
  23. });
  24. exports.command = new command_1.Command("ext:configure <extensionInstanceId>")
  25. .description("configure an existing extension instance")
  26. .withForce()
  27. .option("--local", "deprecated")
  28. .before(requirePermissions_1.requirePermissions, [
  29. "firebaseextensions.instances.update",
  30. "firebaseextensions.instances.get",
  31. ])
  32. .before(checkMinRequiredVersion_1.checkMinRequiredVersion, "extMinVersion")
  33. .before(extensionsHelper_1.diagnoseAndFixProject)
  34. .action(async (instanceId, options) => {
  35. var _a;
  36. const projectId = (0, projectUtils_1.getProjectId)(options);
  37. if (options.nonInteractive) {
  38. throw new error_1.FirebaseError(`Command not supported in non-interactive mode, edit ./extensions/${instanceId}.env directly instead. ` +
  39. `See https://firebase.google.com/docs/extensions/manifest for more details.`);
  40. }
  41. if (options.local) {
  42. 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.");
  43. }
  44. const config = manifest.loadConfig(options);
  45. const refOrPath = manifest.getInstanceTarget(instanceId, config);
  46. const isLocalSource = (0, extensionsHelper_1.isLocalPath)(refOrPath);
  47. let spec;
  48. if (isLocalSource) {
  49. const source = await (0, extensionsHelper_1.createSourceFromLocation)((0, projectUtils_1.needProjectId)({ projectId }), refOrPath);
  50. spec = source.spec;
  51. }
  52. else {
  53. const extensionVersion = await extensionsApi.getExtensionVersion(refOrPath);
  54. spec = extensionVersion.spec;
  55. }
  56. const oldParamValues = manifest.readInstanceParam({
  57. instanceId,
  58. projectDir: config.projectDir,
  59. });
  60. const [immutableParams, tbdParams] = (0, functional_1.partition)(spec.params.concat((_a = spec.systemParams) !== null && _a !== void 0 ? _a : []), (param) => { var _a; return (_a = param.immutable) !== null && _a !== void 0 ? _a : false; });
  61. infoImmutableParams(immutableParams, oldParamValues);
  62. paramHelper.setNewDefaults(tbdParams, oldParamValues);
  63. const mutableParamsBindingOptions = await paramHelper.getParams({
  64. projectId,
  65. paramSpecs: tbdParams,
  66. nonInteractive: false,
  67. paramsEnvPath: "",
  68. instanceId,
  69. reconfiguring: true,
  70. });
  71. const eventsConfig = spec.events
  72. ? await askUserForEventsConfig.askForEventsConfig(spec.events, "${param:PROJECT_ID}", instanceId)
  73. : undefined;
  74. if (eventsConfig) {
  75. mutableParamsBindingOptions.EVENTARC_CHANNEL = { baseValue: eventsConfig.channel };
  76. mutableParamsBindingOptions.ALLOWED_EVENT_TYPES = {
  77. baseValue: eventsConfig.allowedEventTypes.join(","),
  78. };
  79. }
  80. const newParamOptions = Object.assign(Object.assign({}, (0, paramHelper_1.buildBindingOptionsWithBaseValue)(oldParamValues)), mutableParamsBindingOptions);
  81. await manifest.writeToManifest([
  82. {
  83. instanceId,
  84. ref: !isLocalSource ? refs.parse(refOrPath) : undefined,
  85. localPath: isLocalSource ? refOrPath : undefined,
  86. params: newParamOptions,
  87. extensionSpec: spec,
  88. },
  89. ], config, {
  90. nonInteractive: false,
  91. force: true,
  92. });
  93. manifest.showPostDeprecationNotice();
  94. return;
  95. });
  96. function infoImmutableParams(immutableParams, paramValues) {
  97. if (!immutableParams.length) {
  98. return;
  99. }
  100. const plural = immutableParams.length > 1;
  101. utils.logLabeledWarning(extensionsHelper_1.logPrefix, marked(`The following param${plural ? "s are" : " is"} immutable and won't be changed:`));
  102. for (const { param } of immutableParams) {
  103. logger_1.logger.info(`param: ${param}, value: ${paramValues[param]}`);
  104. }
  105. logger_1.logger.info((plural
  106. ? "To set different values for these params"
  107. : "To set a different value for this param") +
  108. ", uninstall the extension, then install a new instance of this extension.");
  109. }