No Description
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.

ext-dev-deprecate.js 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const clc = require("colorette");
  5. const semver = require("semver");
  6. const refs = require("../extensions/refs");
  7. const utils = require("../utils");
  8. const command_1 = require("../command");
  9. const prompt_1 = require("../prompt");
  10. const extensionsHelper_1 = require("../extensions/extensionsHelper");
  11. const extensionsApi_1 = require("../extensions/extensionsApi");
  12. const versionHelper_1 = require("../extensions/versionHelper");
  13. const requireAuth_1 = require("../requireAuth");
  14. const error_1 = require("../error");
  15. exports.command = new command_1.Command("ext:dev:deprecate <extensionRef> <versionPredicate>")
  16. .description("deprecate extension versions that match the version predicate")
  17. .option("-m, --message <deprecationMessage>", "deprecation message")
  18. .option("-f, --force", "override deprecation message for existing deprecated extension versions that match")
  19. .before(requireAuth_1.requireAuth)
  20. .before(extensionsHelper_1.ensureExtensionsApiEnabled)
  21. .action(async (extensionRef, versionPredicate, options) => {
  22. const { publisherId, extensionId, version } = refs.parse(extensionRef);
  23. if (version) {
  24. throw new error_1.FirebaseError(`The input extension reference must be of the format ${clc.bold("<publisherId>/<extensionId>")}. Version should be supplied in the version predicate argument.`);
  25. }
  26. if (!publisherId || !extensionId) {
  27. throw new error_1.FirebaseError(`Error parsing publisher ID and extension ID from extension reference '${clc.bold(extensionRef)}'. Please use the format '${clc.bold("<publisherId>/<extensionId>")}'.`);
  28. }
  29. const { comparator, targetSemVer } = (0, versionHelper_1.parseVersionPredicate)(versionPredicate);
  30. const filter = `id${comparator}"${targetSemVer}"`;
  31. const extensionVersions = await (0, extensionsApi_1.listExtensionVersions)(extensionRef, filter);
  32. const filteredExtensionVersions = extensionVersions
  33. .sort((ev1, ev2) => {
  34. return -semver.compare(ev1.spec.version, ev2.spec.version);
  35. })
  36. .filter((extensionVersion) => {
  37. if (extensionVersion.state === "DEPRECATED" && !options.force) {
  38. return false;
  39. }
  40. const message = extensionVersion.state === "DEPRECATED" ? ", will overwrite deprecation message" : "";
  41. utils.logLabeledBullet(extensionVersion.ref, extensionVersion.state + message);
  42. return true;
  43. });
  44. if (filteredExtensionVersions.length > 0) {
  45. if (!options.force) {
  46. const confirmMessage = "You are about to deprecate these extension version(s). Do you wish to continue?";
  47. const consent = await (0, prompt_1.promptOnce)({
  48. type: "confirm",
  49. message: confirmMessage,
  50. default: false,
  51. });
  52. if (!consent) {
  53. throw new error_1.FirebaseError("Deprecation canceled.");
  54. }
  55. }
  56. }
  57. else {
  58. throw new error_1.FirebaseError("No extension versions matched the version predicate.");
  59. }
  60. await utils.allSettled(filteredExtensionVersions.map(async (extensionVersion) => {
  61. await (0, extensionsApi_1.deprecateExtensionVersion)(extensionVersion.ref, options.deprecationMessage);
  62. }));
  63. utils.logLabeledSuccess(extensionsHelper_1.logPrefix, "successfully deprecated extension version(s).");
  64. });