builder/lib/tasks/bundlers/generateManifestBundle.js

  1. const log = require("@ui5/logger").getLogger("builder:tasks:bundlers:generateManifestBundle");
  2. const manifestBundler = require("../../processors/bundlers/manifestBundler");
  3. const DESCRIPTOR = "manifest.json";
  4. const PROPERTIES_EXT = ".properties";
  5. const BUNDLE_NAME = "manifest-bundle.zip";
  6. /**
  7. *
  8. * @public
  9. * @typedef {object} ManifestBundlerOptions
  10. * @property {string} projectName Project Name
  11. * @property {string} namespace Namespace
  12. */
  13. /**
  14. * Task for manifestBundler.
  15. *
  16. * @public
  17. * @alias module:@ui5/builder.tasks.generateManifestBundle
  18. * @param {object} parameters Parameters
  19. * @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
  20. * @param {ManifestBundlerOptions} parameters.options Options
  21. * @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
  22. */
  23. module.exports = async function({workspace, options = {}}) {
  24. const {projectName, namespace} = options;
  25. if (!projectName || !namespace) {
  26. throw new Error("[generateManifestBundle]: One or more mandatory options not provided");
  27. }
  28. const allResources = await workspace.byGlob(`/resources/${namespace}/**/{${DESCRIPTOR},*${PROPERTIES_EXT}}`);
  29. if (allResources.length === 0) {
  30. log.verbose(`Could not find a "${DESCRIPTOR}" file for project ${projectName}, ` +
  31. `creation of "${BUNDLE_NAME}" is skipped!`);
  32. return;
  33. }
  34. const processedResources = await manifestBundler({
  35. resources: allResources,
  36. options: {
  37. descriptor: DESCRIPTOR,
  38. propertiesExtension: PROPERTIES_EXT,
  39. bundleName: BUNDLE_NAME,
  40. namespace
  41. }
  42. });
  43. await Promise.all(processedResources.map((resource) => {
  44. return workspace.write(resource);
  45. }));
  46. };