builder/lib/tasks/uglify.js

  1. const uglifyProcessor = require("../processors/uglifier");
  2. /**
  3. * Task to minify resources.
  4. *
  5. * @public
  6. * @alias module:@ui5/builder.tasks.uglify
  7. * @param {object} parameters Parameters
  8. * @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
  9. * @param {module:@ui5/builder.tasks.TaskUtil|object} [parameters.taskUtil] TaskUtil
  10. * @param {object} parameters.options Options
  11. * @param {string} parameters.options.pattern Pattern to locate the files to be processed
  12. * @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
  13. */
  14. module.exports = function({workspace, taskUtil, options: {pattern}}) {
  15. return workspace.byGlobSource(pattern)
  16. .then((allResources) => {
  17. let resources = allResources;
  18. if (taskUtil) {
  19. resources = allResources.filter((resource) => {
  20. return !taskUtil.getTag(resource, taskUtil.STANDARD_TAGS.IsBundle);
  21. });
  22. }
  23. return uglifyProcessor({
  24. resources
  25. });
  26. })
  27. .then((processedResources) => {
  28. return Promise.all(processedResources.map((resource) => {
  29. return workspace.write(resource);
  30. }));
  31. });
  32. };