builder/lib/tasks/generateVersionInfo.js

  1. import versionInfoGenerator from "../processors/versionInfoGenerator.js";
  2. const MANIFEST_JSON = "manifest.json";
  3. /**
  4. * @public
  5. * @module @ui5/builder/tasks/generateVersionInfo
  6. */
  7. /**
  8. * Task to create sap-ui-version.json
  9. *
  10. * @public
  11. * @function default
  12. * @static
  13. *
  14. * @param {object} parameters Parameters
  15. * @param {@ui5/fs/DuplexCollection} parameters.workspace DuplexCollection to read and write files
  16. * @param {@ui5/fs/AbstractReader} parameters.dependencies Reader or Collection to read dependency files
  17. * @param {object} parameters.options Options
  18. * @param {string} parameters.options.pattern Glob pattern for .library resources
  19. * @param {object} parameters.options.rootProject DuplexCollection to read and write files
  20. * @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
  21. */
  22. export default async ({workspace, dependencies, options: {rootProject, pattern}}) => {
  23. const resources = await dependencies.byGlob(pattern);
  24. const libraryInfosPromises = resources.map((dotLibResource) => {
  25. const namespace = dotLibResource.getProject().getNamespace();
  26. // pass all required resources to the processor
  27. // the processor will then filter
  28. return dependencies.byGlob(`/resources/${namespace}/**/${MANIFEST_JSON}`).then((manifestResources) => {
  29. const libraryManifest = manifestResources.find((manifestResource) => {
  30. return manifestResource.getPath() === `/resources/${namespace}/${MANIFEST_JSON}`;
  31. });
  32. const embeddedManifests =
  33. manifestResources.filter((manifestResource) => manifestResource !== libraryManifest);
  34. return {
  35. libraryManifest,
  36. embeddedManifests,
  37. name: dotLibResource.getProject().getName(),
  38. version: dotLibResource.getProject().getVersion()
  39. };
  40. });
  41. });
  42. const libraryInfos = await Promise.all(libraryInfosPromises);
  43. const [versionInfoResource] = await versionInfoGenerator({
  44. options: {
  45. rootProjectName: rootProject.getName(),
  46. rootProjectVersion: rootProject.getVersion(),
  47. libraryInfos
  48. }
  49. });
  50. return workspace.write(versionInfoResource);
  51. };