builder/lib/processors/stringReplacer.js

  1. /**
  2. * @public
  3. * @module @ui5/builder/processors/stringReplacer
  4. */
  5. /**
  6. * Replaces placeholders with corresponding values.
  7. *
  8. * @public
  9. * @function default
  10. * @static
  11. *
  12. * @param {object} parameters Parameters
  13. * @param {@ui5/fs/Resource[]} parameters.resources List of resources to be processed
  14. * @param {object} parameters.options Options
  15. * @param {string} parameters.options.pattern Pattern of placeholders
  16. * @param {string} parameters.options.replacement Replacement for placeholders
  17. * @returns {Promise<@ui5/fs/Resource[]>} Promise resolving with modified resources
  18. */
  19. export default function({resources, options: {pattern, replacement}}) {
  20. return Promise.all(resources.map(async (resource) => {
  21. const content = await resource.getString();
  22. const newContent = content.replaceAll(pattern, replacement);
  23. if (content !== newContent) {
  24. resource.setString(newContent);
  25. }
  26. return resource;
  27. }));
  28. }