version-changes.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. /**
  3. * @license
  4. * Copyright Google LLC All Rights Reserved.
  5. *
  6. * Use of this source code is governed by an MIT-style license that can be
  7. * found in the LICENSE file at https://angular.io/license
  8. */
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. const schematics_1 = require("@angular-devkit/schematics");
  11. const target_version_1 = require("./target-version");
  12. /**
  13. * Gets the changes for a given target version from the specified version changes object.
  14. *
  15. * For readability and a good overview of breaking changes, the version change data always
  16. * includes the related Pull Request link. Since this data is not needed when performing the
  17. * upgrade, this unused data can be removed and the changes data can be flattened into an
  18. * easy iterable array.
  19. */
  20. function getChangesForTarget(target, data) {
  21. if (!data) {
  22. throw new schematics_1.SchematicsException(`No data could be found for target version: ${target_version_1.TargetVersion[target]}`);
  23. }
  24. if (!data[target]) {
  25. return [];
  26. }
  27. return data[target].reduce((result, prData) => result.concat(prData.changes), []);
  28. }
  29. exports.getChangesForTarget = getChangesForTarget;
  30. /**
  31. * Gets all changes from the specified version changes object. This is helpful in case a migration
  32. * rule does not distinguish data based on the target version, but for readability the
  33. * upgrade data is separated for each target version.
  34. */
  35. function getAllChanges(data) {
  36. return Object.keys(data)
  37. .map(targetVersion => getChangesForTarget(targetVersion, data))
  38. .reduce((result, versionData) => result.concat(versionData), []);
  39. }
  40. exports.getAllChanges = getAllChanges;
  41. //# sourceMappingURL=version-changes.js.map