builder/lib/tasks/generateResourcesJson.js

  1. "use strict";
  2. const resourceListCreator = require("../processors/resourceListCreator");
  3. const DEFAULT_EXCLUDES = [
  4. /*
  5. * exclude mac metadata files
  6. */
  7. "!**/.DS_Store",
  8. /*
  9. * sap-ui-version.json is not part of the resources
  10. */
  11. "!/resources/sap-ui-version.json"
  12. ];
  13. function getCreatorOptions(projectName) {
  14. const creatorOptions = {};
  15. // TODO: Move configuration into ui5.yaml
  16. if ( projectName === "sap.ui.core" ) {
  17. Object.assign(creatorOptions, {
  18. externalResources: {
  19. "sap/ui/core": [
  20. "*",
  21. "sap/base/",
  22. "sap/ui/"
  23. ]
  24. }
  25. });
  26. } else if ( projectName === "sap.ui.integration" ) {
  27. Object.assign(creatorOptions, {
  28. externalResources: {
  29. "sap/ui/integration": [
  30. "sap-ui-integration*.js",
  31. ]
  32. }
  33. });
  34. }
  35. return creatorOptions;
  36. }
  37. /**
  38. * Task for creating a resources.json file, describing all productive build resources.
  39. *
  40. * <p>
  41. * The detailed structure can be found in the documentation:
  42. * {@link https://sdk.openui5.org/topic/adcbcf8b50924556ab3f321fcd9353ea}
  43. * </p>
  44. *
  45. * <p>
  46. * Not supported in combination with task {@link module:@ui5/builder.tasks.generateStandaloneAppBundle}.
  47. * Therefore it is also not supported in combination with self-contained build.
  48. * </p>
  49. *
  50. * @example <caption>sample resources.json</caption>
  51. * const resourcesJson = {
  52. * "_version": "1.1.0",
  53. * "resources": [
  54. * {
  55. * "name": "Component-preload.js",
  56. * "module": "application/mine/Component-preload.js",
  57. * "size": 3746,
  58. * "merged": true,
  59. * "included": [
  60. * "application/mine/Component.js",
  61. * "application/mine/changes/coding/MyExtension.js",
  62. * "application/mine/changes/flexibility-bundle.json",
  63. * "application/mine/changes/fragments/MyFragment.fragment.xml",
  64. * "application/mine/manifest.json"
  65. * ]
  66. * },
  67. * {
  68. * "name": "resources.json",
  69. * "size": 1870
  70. * },
  71. * {
  72. * "name": "rules/Button-dbg.support.js",
  73. * "module": "application/mine/rules/Button.support.js",
  74. * "size": 211,
  75. * "format": "raw",
  76. * "isDebug": true,
  77. * "required": [
  78. * "application/mine/library.js",
  79. * "sap/ui/core/Control.js"
  80. * ],
  81. * "condRequired": [
  82. * "application/mine/changeHandler/SplitButton.js",
  83. * "sap/ui/core/format/DateFormat.js"
  84. * ],
  85. * "dynRequired": true,
  86. * "support": true
  87. * }
  88. * ]
  89. * };
  90. *
  91. * @public
  92. * @alias module:@ui5/builder.tasks.generateResourcesJson
  93. * @param {object} parameters Parameters
  94. * @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
  95. * @param {module:@ui5/fs.AbstractReader} [parameters.dependencies] Reader or Collection to read dependency files
  96. * @param {object} parameters.options Options
  97. * @param {string} parameters.options.projectName Project name
  98. * @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
  99. */
  100. module.exports = async function({workspace, dependencies, options: {projectName}}) {
  101. const resources = await workspace.byGlob(["/resources/**/*"].concat(DEFAULT_EXCLUDES));
  102. // TODO 3.0: Make dependencies parameter mandatory
  103. let dependencyResources;
  104. if (dependencies) {
  105. dependencyResources =
  106. await dependencies.byGlob("/resources/**/*.{js,json,xml,html,properties,library}");
  107. }
  108. const resourceLists = await resourceListCreator({
  109. resources,
  110. dependencyResources,
  111. options: getCreatorOptions(projectName),
  112. });
  113. await Promise.all(
  114. resourceLists.map((resourceList) => workspace.write(resourceList))
  115. );
  116. };