builder/lib/tasks/bundlers/generateBundle.js

  1. const moduleBundler = require("../../processors/bundlers/moduleBundler");
  2. const ReaderCollectionPrioritized = require("@ui5/fs").ReaderCollectionPrioritized;
  3. /**
  4. * Generates a bundle based on the given bundle definition
  5. *
  6. * @public
  7. * @alias module:@ui5/builder.tasks.generateBundle
  8. * @param {object} parameters Parameters
  9. * @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
  10. * @param {module:@ui5/fs.ReaderCollection} parameters.dependencies Collection to read dependency files
  11. * @param {module:@ui5/builder.tasks.TaskUtil|object} [parameters.taskUtil] TaskUtil
  12. * @param {object} parameters.options Options
  13. * @param {string} parameters.options.projectName Project name
  14. * @param {ModuleBundleDefinition} parameters.options.bundleDefinition Module bundle definition
  15. * @param {ModuleBundleOptions} parameters.options.bundleOptions Module bundle options
  16. * @returns {Promise} Promise resolving with <code>undefined</code> once data has been written
  17. */
  18. module.exports = function({
  19. workspace, dependencies, taskUtil, options: {projectName, bundleDefinition, bundleOptions}
  20. }) {
  21. const combo = new ReaderCollectionPrioritized({
  22. name: `libraryBundler - prioritize workspace over dependencies: ${projectName}`,
  23. readers: [workspace, dependencies]
  24. });
  25. return combo.byGlob("/resources/**/*.{js,json,xml,html,properties,library}").then((resources) => {
  26. return moduleBundler({
  27. options: {
  28. bundleDefinition,
  29. bundleOptions
  30. },
  31. resources
  32. }).then((bundles) => {
  33. return Promise.all(bundles.map((bundle) => {
  34. if (taskUtil) {
  35. taskUtil.setTag(bundle, taskUtil.STANDARD_TAGS.IsBundle);
  36. }
  37. return workspace.write(bundle);
  38. }));
  39. });
  40. });
  41. };