Ingen beskrivning
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ext-update.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 checkMinRequiredVersion_1 = require("../checkMinRequiredVersion");
  8. const command_1 = require("../command");
  9. const error_1 = require("../error");
  10. const extensionsApi = require("../extensions/extensionsApi");
  11. const extensionsHelper_1 = require("../extensions/extensionsHelper");
  12. const paramHelper = require("../extensions/paramHelper");
  13. const updateHelper_1 = require("../extensions/updateHelper");
  14. const refs = require("../extensions/refs");
  15. const projectUtils_1 = require("../projectUtils");
  16. const requirePermissions_1 = require("../requirePermissions");
  17. const utils = require("../utils");
  18. const experiments = require("../experiments");
  19. const manifest = require("../extensions/manifest");
  20. const askUserForEventsConfig = require("../extensions/askUserForEventsConfig");
  21. marked.setOptions({
  22. renderer: new TerminalRenderer(),
  23. });
  24. exports.command = new command_1.Command("ext:update <extensionInstanceId> [updateSource]")
  25. .description(experiments.isEnabled("extdev")
  26. ? "update an existing extension instance to the latest version or from a local or URL source"
  27. : "update an existing extension instance to the latest version")
  28. .before(requirePermissions_1.requirePermissions, [
  29. "firebaseextensions.instances.update",
  30. "firebaseextensions.instances.get",
  31. ])
  32. .before(extensionsHelper_1.ensureExtensionsApiEnabled)
  33. .before(checkMinRequiredVersion_1.checkMinRequiredVersion, "extMinVersion")
  34. .before(extensionsHelper_1.diagnoseAndFixProject)
  35. .option("--local", "deprecated")
  36. .withForce()
  37. .action(async (instanceId, updateSource, options) => {
  38. const projectId = (0, projectUtils_1.getProjectId)(options);
  39. const config = manifest.loadConfig(options);
  40. if (options.local) {
  41. 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.");
  42. }
  43. const oldRefOrPath = manifest.getInstanceTarget(instanceId, config);
  44. if ((0, extensionsHelper_1.isLocalPath)(oldRefOrPath)) {
  45. throw new error_1.FirebaseError(`Updating an extension with local source is not neccessary. ` +
  46. `Rerun "firebase deploy" or restart the emulator after making changes to your local extension source. ` +
  47. `If you've edited the extension param spec, you can edit an extension instance's params ` +
  48. `interactively by running "firebase ext:configure --local {instance-id}"`);
  49. }
  50. const oldRef = manifest.getInstanceRef(instanceId, config);
  51. const oldExtensionVersion = await extensionsApi.getExtensionVersion(refs.toExtensionVersionRef(oldRef));
  52. updateSource = (0, updateHelper_1.inferUpdateSource)(updateSource, refs.toExtensionRef(oldRef));
  53. const newSourceOrigin = (0, extensionsHelper_1.getSourceOrigin)(updateSource);
  54. if (![extensionsHelper_1.SourceOrigin.PUBLISHED_EXTENSION, extensionsHelper_1.SourceOrigin.PUBLISHED_EXTENSION_VERSION].includes(newSourceOrigin)) {
  55. throw new error_1.FirebaseError(`Only updating to a published extension version is allowed`);
  56. }
  57. const newExtensionVersion = await extensionsApi.getExtensionVersion(updateSource);
  58. if (oldExtensionVersion.ref === newExtensionVersion.ref) {
  59. utils.logLabeledBullet(extensionsHelper_1.logPrefix, `${clc.bold(instanceId)} is already up to date. Its version is ${clc.bold(newExtensionVersion.ref)}.`);
  60. return;
  61. }
  62. utils.logLabeledBullet(extensionsHelper_1.logPrefix, `Updating ${clc.bold(instanceId)} from version ${clc.bold(oldExtensionVersion.ref)} to version ${clc.bold(newExtensionVersion.ref)}.`);
  63. if (!(await (0, extensionsHelper_1.confirm)({
  64. nonInteractive: options.nonInteractive,
  65. force: options.force,
  66. default: false,
  67. }))) {
  68. utils.logLabeledBullet(extensionsHelper_1.logPrefix, "Update aborted.");
  69. return;
  70. }
  71. const oldParamValues = manifest.readInstanceParam({
  72. instanceId,
  73. projectDir: config.projectDir,
  74. });
  75. const newParamBindingOptions = await paramHelper.getParamsForUpdate({
  76. spec: oldExtensionVersion.spec,
  77. newSpec: newExtensionVersion.spec,
  78. currentParams: oldParamValues,
  79. projectId,
  80. paramsEnvPath: "",
  81. nonInteractive: options.nonInteractive,
  82. instanceId,
  83. });
  84. const eventsConfig = newExtensionVersion.spec.events
  85. ? await askUserForEventsConfig.askForEventsConfig(newExtensionVersion.spec.events, "${param:PROJECT_ID}", instanceId)
  86. : undefined;
  87. if (eventsConfig) {
  88. newParamBindingOptions.EVENTARC_CHANNEL = { baseValue: eventsConfig.channel };
  89. newParamBindingOptions.ALLOWED_EVENT_TYPES = {
  90. baseValue: eventsConfig.allowedEventTypes.join(","),
  91. };
  92. }
  93. await manifest.writeToManifest([
  94. {
  95. instanceId,
  96. ref: refs.parse(newExtensionVersion.ref),
  97. params: newParamBindingOptions,
  98. extensionSpec: newExtensionVersion.spec,
  99. extensionVersion: newExtensionVersion,
  100. },
  101. ], config, {
  102. nonInteractive: options.nonInteractive,
  103. force: true,
  104. });
  105. manifest.showPostDeprecationNotice();
  106. return;
  107. });