builder/lib/tasks/replaceVersion.js

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