builder/lib/tasks/replaceVersion.js

  1. import stringReplacer from "../processors/stringReplacer.js";
  2. /**
  3. * @public
  4. * @module @ui5/builder/tasks/replaceVersion
  5. */
  6. /**
  7. * Task to replace the version <code>${version}</code>.
  8. *
  9. * @public
  10. * @function default
  11. * @static
  12. *
  13. * @param {object} parameters Parameters
  14. * @param {@ui5/fs/DuplexCollection} parameters.workspace DuplexCollection to read and write files
  15. * @param {object} parameters.options Options
  16. * @param {string} parameters.options.pattern Pattern to locate the files to be processed
  17. * @param {string} parameters.options.version Replacement version
  18. * @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
  19. */
  20. export default function({workspace, options: {pattern, version}}) {
  21. return workspace.byGlob(pattern)
  22. .then((allResources) => {
  23. return stringReplacer({
  24. resources: allResources,
  25. options: {
  26. pattern: /\$\{(?:project\.)?version\}/g,
  27. replacement: version
  28. }
  29. });
  30. })
  31. .then((processedResources) => {
  32. return Promise.all(processedResources.map((resource) => {
  33. return workspace.write(resource);
  34. }));
  35. });
  36. }