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 5 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
65 changes: 58 additions & 7 deletions lib/processors/bundlers/flexChangesBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,70 @@ 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) {
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) {
switch (content.fileType) {
case "change":
if (content.appDescriptorChange && (content.appDescriptorChange === "true" || content.appDescriptorChange == true)) {
break;
}
if (content.variantReference && content.variantReference !== "") {
variantDependentControlChangeList.push(content);
} else {
changeList.push(content);
}
break;
case "variant":
compVariantList.push(content);
break;
case "ctrl_variant":
variantList.push(content);
break;
case "ctrl_variant_change":
variantChangeList.push(content);
break;
case "ctrl_variant_management_change":
variantManagementChangeList.push(content);
break;
}
});
return changesContent;

if (!options.hasFlexBundleVersion && (compVariantList.length != 0 || variantList.length != 0 || variantChangeList.length != 0 || variantDependentControlChangeList.length != 0 || variantManagementChangeList.length != 0)) {
throw new Error("There are some control variant change in the changes folder. This only works with a minUI5Version 1.73.0. Please update the minUI5Version in the manifest.json minimum to 1.73.0");
codeworrior marked this conversation as resolved.
Show resolved Hide resolved
}
// create changes-bundle.json
if (!options.hasFlexBundleVersion) {
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 +85,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
36 changes: 30 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.73 flexibility-bundle.json will be create.
* If there a ctrl_variants and minUI5Version < 1.73 build will break and throw an error.
codeworrior marked this conversation as resolved.
Show resolved Hide resolved
*
* @public
* @alias module:@ui5/builder.tasks.generateFlexChangesBundle
Expand Down Expand Up @@ -51,15 +53,37 @@ 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) => {
let hasFlexBundleVersion = false;
if (parseFloat(version) >= 1.73) {
codeworrior marked this conversation as resolved.
Show resolved Hide resolved
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 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