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 1 commit
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
55 changes: 48 additions & 7 deletions lib/processors/bundlers/flexChangesBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,60 @@ 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.72 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) {
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 changeList = [];
const variantDependentControlChangeList = [];
const compVariantList = [];
const variantList = [];
const variantChangeList = [];
const variantManagementChangeList = [];

changesContent.forEach(function(content) {
if (content.fileType == "change") {
if (content.appDescriptorChange && (content.appDescriptorChange == "true" || content.appDescriptorChange == true)) {
compVariantList.push(content);
} else {
if (content.variantReference && content.variantReference != "") {
variantDependentControlChangeList.push(content);
} else {
changeList.push(content);
}
}
} else if (content.fileType == "ctrl_variant") {
variantList.push(content);
} else if (content.fileType == "ctrl_variant_change") {
variantChangeList.push(content);
} else if (content.fileType == "ctrl_variant_management_change") {
variantManagementChangeList.push(content);
}
});
return changesContent;

// create changes-bundle.json
if (!options.hasFlexBundleVersion && compVariantList.length == 0 && variantList.length == 0 && variantChangeList.length == 0 && variantDependentControlChangeList.length == 0 && variantManagementChangeList.length == 0) {
return JSON.stringify(changeList);
} else {
bundleName = "flexibility-bundle.json";
const newChangeFormat = {};
newChangeFormat.changes = changeList;
newChangeFormat.compVariants = compVariantList;
newChangeFormat.variants = variantList;
newChangeFormat.variantChanges = variantChangeList;
newChangeFormat.variantDependentControlChanges = variantDependentControlChangeList;
codeworrior marked this conversation as resolved.
Show resolved Hide resolved
newChangeFormat.variantManagementChanges = variantManagementChangeList;

return JSON.stringify(newChangeFormat);
}
}

return Promise.all(resources.map((resource) => {
Expand All @@ -34,10 +75,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,
codeworrior marked this conversation as resolved.
Show resolved Hide resolved
string: changesContent
}));
}
return result;
Expand Down
47 changes: 41 additions & 6 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.72 flexibility-bundle.json will be create.
* If there a ctrl_variants minUI5Version will update to 1.72 if it is below and flexibility-bundle.json will be create.
*
* @public
* @alias module:@ui5/builder.tasks.generateFlexChangesBundle
Expand All @@ -22,6 +24,8 @@ module.exports = function({workspace, options}) {
if (options && options.namespace) {
pathPrefix = `/resources/${options.namespace}`;
}
let hasVariant = false;
let hasFlexBundleVersion = false;

function updateJson(data) {
// ensure the existence of the libs section in the dependencies
Expand All @@ -39,6 +43,12 @@ module.exports = function({workspace, options}) {
log.verbose("sap.ui.fl not found in manifest.json, inserting it...");
mLibs["sap.ui.fl"] = {};
}

// if there are ctrl variant and minUI5Version < 1.72 need to update minUI5Version to 1.72.0
if (hasVariant && !hasFlexBundleVersion) {
log.verbose("minUI5Version < 1.72, updated it to 1.72.0");
data["sap.ui5"].dependencies.minUI5Version = "1.72.0";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, the tooling must not change manifest metadata on the fly, it should rather stop with an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I change the logic.
The build will stop when the minUI5Version is below 1.72 and there are control variants in the change folder

}
}

async function updateFLdependency() {
Expand All @@ -51,15 +61,36 @@ module.exports = function({workspace, options}) {
await workspace.write(manifestResource);
}

function readManifestMinUI5Version() {
return workspace.byPath(`${pathPrefix}/manifest.json`).then((manifestResource) => {
if (manifestResource) {
return manifestResource.getBuffer().then((buffer) => {
return JSON.parse(buffer.toString());
});
}
return {};
}).then((manifestContent) => {
codeworrior marked this conversation as resolved.
Show resolved Hide resolved
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
return readManifestMinUI5Version().then((version) => {
if (parseFloat(version) >= 1.72) {
hasFlexBundleVersion = true;
}
return flexChangesBundler({
resources: allResources,
options: {
namespace: options.namespace,
pathPrefix: pathPrefix,
codeworrior marked this conversation as resolved.
Show resolved Hide resolved
hasFlexBundleVersion: hasFlexBundleVersion
}
});
});
})
.then((processedResources) => {
Expand All @@ -69,6 +100,10 @@ module.exports = function({workspace, options}) {
})).then(async () => {
// Add the sap.ui.fl dependency if a bundle has been created
if (processedResources.length > 0) {
// flexibility-bundle.json can be create when there are ctrl variant even though minUI5Version is below 1.72
if (processedResources[0]._name == "flexibility-bundle.json") {
hasVariant = true;
}
await updateFLdependency();
}
});
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":"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}],"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,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.72.0",
"libs": {
"sap.ui.layout": {},
"sap.ui.core": {},
Expand Down
12 changes: 12 additions & 0 deletions test/expected/build/application.k/dest/Component-preload.js

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

1 change: 1 addition & 0 deletions test/expected/build/application.k/dest/Component.js

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

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sap.ui.define([],function(){return{}});
Loading