Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] flexChangesBundler: Add flexibility-bundle.json #353

Merged
merged 7 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 65 additions & 7 deletions lib/processors/bundlers/flexChangesBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,77 @@ const resourceFactory = require("@ui5/fs").resourceFactory;
* @param {module:@ui5/fs.Resource[]} parameters.resources List of resources to be processed
* @param {Object} parameters.options Options
* @param {string} parameters.options.pathPrefix Prefix for bundle path
* @param {string} parameters.options.hasFlexBundleVersion true if minUI5Version >= 1.73 than create flexibility-bundle.json
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving with flex changes bundle resources
*/
module.exports = function({resources, options}) {
let bundleName = "changes-bundle.json";

function sortByTimeStamp(a, b) {
return a.creation > b.creation ? 1 : -1;
}

function sortAndStringify(changesContent) {
/**
* bundle changes resource to json string
*
* @param {Array} changesContent Array of resources files
* @returns {string} Json sting of changes and control variants
*/
function sortAndStringifyInFlexFormat(changesContent) {
codeworrior marked this conversation as resolved.
Show resolved Hide resolved
changesContent = changesContent.sort(sortByTimeStamp);
changesContent = changesContent.map(function(change) {
return JSON.stringify(change);
const changes = [];
const variantDependentControlChanges = [];
const compVariants = [];
const variants = [];
const variantChanges = [];
const variantManagementChanges = [];

changesContent.forEach(function(content) {
switch (content.fileType) {
case "change":
if (content.appDescriptorChange && (content.appDescriptorChange === "true" || content.appDescriptorChange == true)) {
break;
}
if (content.variantReference && content.variantReference !== "") {
variantDependentControlChanges.push(content);
} else {
changes.push(content);
}
break;
case "variant":
compVariants.push(content);
break;
case "ctrl_variant":
variants.push(content);
break;
case "ctrl_variant_change":
variantChanges.push(content);
break;
case "ctrl_variant_management_change":
variantManagementChanges.push(content);
break;
}
});
return changesContent;

if (!options.hasFlexBundleVersion && (compVariants.length != 0 || variants.length != 0 || variantChanges.length != 0 || variantDependentControlChanges.length != 0 || variantManagementChanges.length != 0)) {
throw new Error("There are some control variant changes in the changes folder. This only works with a minUI5Version 1.73.0. Please update the minUI5Version in the manifest.json to 1.73.0 or higher");
}
// create changes-bundle.json
if (!options.hasFlexBundleVersion) {
return JSON.stringify(changes);
} else {
bundleName = "flexibility-bundle.json";
const newChangeFormat = {
changes,
compVariants,
variants,
variantChanges,
variantDependentControlChanges,
variantManagementChanges
};

return JSON.stringify(newChangeFormat);
}
}

return Promise.all(resources.map((resource) => {
Expand All @@ -34,10 +92,10 @@ module.exports = function({resources, options}) {
log.info("Changes collected. Number of changes: " + nNumberOfChanges);
const result = [];
if (nNumberOfChanges > 0) {
changesContent = sortAndStringify(changesContent);
changesContent = sortAndStringifyInFlexFormat(changesContent);
result.push(resourceFactory.createResource({
path: `${options.pathPrefix}/changes/changes-bundle.json`,
string: "[" + changesContent.join(",") + "]"
path: `${options.pathPrefix}/changes/${bundleName}`,
string: changesContent
}));
}
return result;
Expand Down
36 changes: 28 additions & 8 deletions lib/tasks/bundlers/generateFlexChangesBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const flexChangesBundler = require("../../processors/bundlers/flexChangesBundler
* at runtime.
* If a change bundle is created, "sap.ui.fl" is added as a dependency to the manifest.json if not already present -
* if the dependency is already listed but lazy-loaded, lazy loading is disabled.
* If minUI5Version >= 1.73 flexibility-bundle.json will be create.
* If there are control variants and minUI5Version < 1.73 build will break and throw an error.
*
* @public
* @alias module:@ui5/builder.tasks.generateFlexChangesBundle
Expand Down Expand Up @@ -51,16 +53,34 @@ module.exports = function({workspace, options}) {
await workspace.write(manifestResource);
}

async function readManifestMinUI5Version() {
const manifestResource = await workspace.byPath(`${pathPrefix}/manifest.json`);
const manifestContent = JSON.parse(await manifestResource.getString());

manifestContent["sap.ui5"] = manifestContent["sap.ui5"] || {};
manifestContent["sap.ui5"].dependencies = manifestContent["sap.ui5"].dependencies || {};
return manifestContent["sap.ui5"].dependencies.minUI5Version = manifestContent["sap.ui5"].dependencies.minUI5Version || "";
}

log.verbose("Collecting flexibility changes");
return workspace.byGlob(`${pathPrefix}/changes/*.change`)
return workspace.byGlob(`${pathPrefix}/changes/*.{change,variant,ctrl_variant,ctrl_variant_change,ctrl_variant_management_change}`)
.then((allResources) => {
return flexChangesBundler({
resources: allResources,
options: {
namespace: options.namespace,
pathPrefix: pathPrefix
}
});
if (allResources.length > 0) {
return readManifestMinUI5Version().then((version) => {
let hasFlexBundleVersion = false;
if (parseFloat(version) >= 1.73) {
hasFlexBundleVersion = true;
}
return flexChangesBundler({
resources: allResources,
options: {
pathPrefix,
hasFlexBundleVersion
}
});
});
}
return [];
})
.then((processedResources) => {
return Promise.all(processedResources.map((resource) => {
Expand Down
4 changes: 2 additions & 2 deletions test/expected/build/application.j/dest/Component-preload.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"changes":[{"fileName":"id_456_addField","fileType":"change","changeType":"hideControl","component":"application.j.Component","content":{},"selector":{"id":"control1"},"layer":"VENDOR","texts":{},"namespace":"apps/application.j.Component/changes","creation":"2023-10-30T13:52:40.4754350Z","originalLanguage":"","conditions":{},"support":{"generator":"did it","user":"Max Mustermann"}},{"fileName":"id_123_addField","fileType":"change","changeType":"hideControl","component":"application.j.Component","content":{},"selector":{"id":"control1"},"layer":"VENDOR","texts":{},"namespace":"apps/application.j.Component/changes","creation":"2025-10-30T13:52:40.4754350Z","originalLanguage":"","conditions":{},"support":{"generator":"did it","user":"Max Mustermann"}}],"compVariants":[{"fileName":"id_111_compVariants","fileType":"variant","changeType":"hideControl","component":"application.j.Component","content":{},"selector":{"id":"control1"},"layer":"VENDOR","texts":{},"namespace":"apps/application.j.Component/changes","creation":"2025-10-30T13:52:40.4754350Z","originalLanguage":"","conditions":{},"support":{"generator":"did it","user":"Max Mustermann"},"appDescriptorChange":false}],"variants":[{"fileName":"id_111_test","fileType":"ctrl_variant","changeType":"hideControl","component":"application.j.Component","content":{},"selector":{"id":"control1"},"layer":"VENDOR","texts":{},"namespace":"apps/application.j.Component/changes","creation":"2025-10-30T13:52:40.4754350Z","originalLanguage":"","conditions":{},"support":{"generator":"did it","user":"Max Mustermann"}}],"variantChanges":[{"fileName":"id_111_test","fileType":"ctrl_variant_change","changeType":"hideControl","component":"application.j.Component","content":{},"selector":{"id":"control1"},"layer":"VENDOR","texts":{},"namespace":"apps/application.j.Component/changes","creation":"2025-10-30T13:52:40.4754350Z","originalLanguage":"","conditions":{},"support":{"generator":"did it","user":"Max Mustermann"}}],"variantDependentControlChanges":[{"fileName":"id_111_variantDependentControlChange","fileType":"change","changeType":"hideControl","component":"application.j.Component","content":{},"selector":{"id":"control1"},"layer":"VENDOR","texts":{},"namespace":"apps/application.j.Component/changes","creation":"2025-10-30T13:52:40.4754350Z","originalLanguage":"","conditions":{},"support":{"generator":"did it","user":"Max Mustermann"},"variantReference":"someting here"}],"variantManagementChanges":[{"fileName":"id_111_test","fileType":"ctrl_variant_management_change","changeType":"hideControl","component":"application.j.Component","content":{},"selector":{"id":"control1"},"layer":"VENDOR","texts":{},"namespace":"apps/application.j.Component/changes","creation":"2025-10-30T13:52:40.4754350Z","originalLanguage":"","conditions":{},"support":{"generator":"did it","user":"Max Mustermann"}}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"fileName": "id_111_compVariants",
"fileType": "change",
"changeType": "hideControl",
"component": "application.j.Component",
"content": {},
"selector": {
"id": "control1"
},
"layer": "VENDOR",
"texts": {},
"namespace": "apps/application.j.Component/changes",
"creation": "2025-10-30T13:52:40.4754350Z",
"originalLanguage": "",
"conditions": {},
"support": {
"generator": "did it",
"user": "Max Mustermann"
},
"appDescriptorChange": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"fileName": "id_111_compVariants",
"fileType": "variant",
"changeType": "hideControl",
"component": "application.j.Component",
"content": {},
"selector": {
"id": "control1"
},
"layer": "VENDOR",
"texts": {},
"namespace": "apps/application.j.Component/changes",
"creation": "2025-10-30T13:52:40.4754350Z",
"originalLanguage": "",
"conditions": {},
"support": {
"generator": "did it",
"user": "Max Mustermann"
},
"appDescriptorChange": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"fileName": "id_111_test",
"fileType": "ctrl_variant",
"changeType": "hideControl",
"component": "application.j.Component",
"content": {},
"selector": {
"id": "control1"
},
"layer": "VENDOR",
"texts": {},
"namespace": "apps/application.j.Component/changes",
"creation": "2025-10-30T13:52:40.4754350Z",
"originalLanguage": "",
"conditions": {},
"support": {
"generator": "did it",
"user": "Max Mustermann"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"fileName": "id_111_test",
"fileType": "ctrl_variant_change",
"changeType": "hideControl",
"component": "application.j.Component",
"content": {},
"selector": {
"id": "control1"
},
"layer": "VENDOR",
"texts": {},
"namespace": "apps/application.j.Component/changes",
"creation": "2025-10-30T13:52:40.4754350Z",
"originalLanguage": "",
"conditions": {},
"support": {
"generator": "did it",
"user": "Max Mustermann"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"fileName": "id_111_test",
"fileType": "ctrl_variant_management_change",
"changeType": "hideControl",
"component": "application.j.Component",
"content": {},
"selector": {
"id": "control1"
},
"layer": "VENDOR",
"texts": {},
"namespace": "apps/application.j.Component/changes",
"creation": "2025-10-30T13:52:40.4754350Z",
"originalLanguage": "",
"conditions": {},
"support": {
"generator": "did it",
"user": "Max Mustermann"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"fileName": "id_111_variantDependentControlChange",
"fileType": "change",
"changeType": "hideControl",
"component": "application.j.Component",
"content": {},
"selector": {
"id": "control1"
},
"layer": "VENDOR",
"texts": {},
"namespace": "apps/application.j.Component/changes",
"creation": "2025-10-30T13:52:40.4754350Z",
"originalLanguage": "",
"conditions": {},
"support": {
"generator": "did it",
"user": "Max Mustermann"
},
"variantReference": "someting here"
}
1 change: 1 addition & 0 deletions test/expected/build/application.j/dest/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"sap.ui5": {
"dependencies": {
"minUI5Version": "1.73.2",
"libs": {
"sap.ui.layout": {},
"sap.ui.core": {},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"fileName": "id_111_compVariants",
"fileType": "change",
"changeType": "hideControl",
"component": "application.j.Component",
"content": {},
"selector": {
"id": "control1"
},
"layer": "VENDOR",
"texts": {},
"namespace": "apps/application.j.Component/changes",
"creation": "2025-10-30T13:52:40.4754350Z",
"originalLanguage": "",
"conditions": {},
"support": {
"generator": "did it",
"user": "Max Mustermann"
},
"appDescriptorChange": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"fileName": "id_111_compVariants",
"fileType": "variant",
"changeType": "hideControl",
"component": "application.j.Component",
"content": {},
"selector": {
"id": "control1"
},
"layer": "VENDOR",
"texts": {},
"namespace": "apps/application.j.Component/changes",
"creation": "2025-10-30T13:52:40.4754350Z",
"originalLanguage": "",
"conditions": {},
"support": {
"generator": "did it",
"user": "Max Mustermann"
},
"appDescriptorChange": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"fileName": "id_111_test",
"fileType": "ctrl_variant",
"changeType": "hideControl",
"component": "application.j.Component",
"content": {},
"selector": {
"id": "control1"
},
"layer": "VENDOR",
"texts": {},
"namespace": "apps/application.j.Component/changes",
"creation": "2025-10-30T13:52:40.4754350Z",
"originalLanguage": "",
"conditions": {},
"support": {
"generator": "did it",
"user": "Max Mustermann"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"fileName": "id_111_test",
"fileType": "ctrl_variant_change",
"changeType": "hideControl",
"component": "application.j.Component",
"content": {},
"selector": {
"id": "control1"
},
"layer": "VENDOR",
"texts": {},
"namespace": "apps/application.j.Component/changes",
"creation": "2025-10-30T13:52:40.4754350Z",
"originalLanguage": "",
"conditions": {},
"support": {
"generator": "did it",
"user": "Max Mustermann"
}
}
Loading