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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.parseChangelog = exports.getLocalChangelog = exports.breakingChangesInUpdate = exports.displayReleaseNotes = exports.getReleaseNotesForUpdate = void 0;
  4. const clc = require("colorette");
  5. const { marked } = require("marked");
  6. const path = require("path");
  7. const semver = require("semver");
  8. const TerminalRenderer = require("marked-terminal");
  9. const Table = require("cli-table");
  10. const extensionsApi_1 = require("./extensionsApi");
  11. const localHelper_1 = require("./localHelper");
  12. const logger_1 = require("../logger");
  13. const refs = require("./refs");
  14. const utils_1 = require("../utils");
  15. marked.setOptions({
  16. renderer: new TerminalRenderer(),
  17. });
  18. const EXTENSIONS_CHANGELOG = "CHANGELOG.md";
  19. const VERSION_LINE_REGEX = /##.*(\d+\.\d+\.\d+(?:-((\d+|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(\d+|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?).*/;
  20. async function getReleaseNotesForUpdate(args) {
  21. const releaseNotes = {};
  22. const filter = `id<="${args.toVersion}" AND id>"${args.fromVersion}"`;
  23. const extensionVersions = await (0, extensionsApi_1.listExtensionVersions)(args.extensionRef, filter);
  24. extensionVersions.sort((ev1, ev2) => {
  25. return -semver.compare(ev1.spec.version, ev2.spec.version);
  26. });
  27. for (const extensionVersion of extensionVersions) {
  28. if (extensionVersion.releaseNotes) {
  29. const version = refs.parse(extensionVersion.ref).version;
  30. releaseNotes[version] = extensionVersion.releaseNotes;
  31. }
  32. }
  33. return releaseNotes;
  34. }
  35. exports.getReleaseNotesForUpdate = getReleaseNotesForUpdate;
  36. function displayReleaseNotes(releaseNotes, fromVersion) {
  37. const versions = [fromVersion].concat(Object.keys(releaseNotes));
  38. const breakingVersions = breakingChangesInUpdate(versions);
  39. const table = new Table({ head: ["Version", "What's New"], style: { head: ["yellow", "bold"] } });
  40. for (const [version, note] of Object.entries(releaseNotes)) {
  41. if (breakingVersions.includes(version)) {
  42. table.push([clc.yellow(clc.bold(version)), marked(note)]);
  43. }
  44. else {
  45. table.push([version, marked(note)]);
  46. }
  47. }
  48. logger_1.logger.info(clc.bold("What's new with this update:"));
  49. if (breakingVersions.length) {
  50. (0, utils_1.logLabeledWarning)("warning", "This is a major version update, which means it may contain breaking changes." +
  51. " Read the release notes carefully before continuing with this update.");
  52. }
  53. logger_1.logger.info(table.toString());
  54. }
  55. exports.displayReleaseNotes = displayReleaseNotes;
  56. function breakingChangesInUpdate(versionsInUpdate) {
  57. const breakingVersions = [];
  58. const semvers = versionsInUpdate.map((v) => semver.parse(v)).sort(semver.compare);
  59. for (let i = 1; i < semvers.length; i++) {
  60. const hasMajorBump = semvers[i - 1].major < semvers[i].major;
  61. const hasMinorBumpInPreview = semvers[i - 1].major === 0 &&
  62. semvers[i].major === 0 &&
  63. semvers[i - 1].minor < semvers[i].minor;
  64. if (hasMajorBump || hasMinorBumpInPreview) {
  65. breakingVersions.push(semvers[i].raw);
  66. }
  67. }
  68. return breakingVersions;
  69. }
  70. exports.breakingChangesInUpdate = breakingChangesInUpdate;
  71. function getLocalChangelog(directory) {
  72. const rawChangelog = (0, localHelper_1.readFile)(path.resolve(directory, EXTENSIONS_CHANGELOG));
  73. return parseChangelog(rawChangelog);
  74. }
  75. exports.getLocalChangelog = getLocalChangelog;
  76. function parseChangelog(rawChangelog) {
  77. const changelog = {};
  78. let currentVersion = "";
  79. for (const line of rawChangelog.split("\n")) {
  80. const matches = line.match(VERSION_LINE_REGEX);
  81. if (matches) {
  82. currentVersion = matches[1];
  83. }
  84. else if (currentVersion) {
  85. if (!changelog[currentVersion]) {
  86. changelog[currentVersion] = line;
  87. }
  88. else {
  89. changelog[currentVersion] += `\n${line}`;
  90. }
  91. }
  92. }
  93. return changelog;
  94. }
  95. exports.parseChangelog = parseChangelog;