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 6 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 is 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");
codeworrior marked this conversation as resolved.
Show resolved Hide resolved
}
// 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
42 changes: 33 additions & 9 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 control 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 All @@ -22,6 +24,8 @@ module.exports = function({workspace, options}) {
if (options && options.namespace) {
pathPrefix = `/resources/${options.namespace}`;
}
let manifestResource = {};
let manifestContent = {};

function updateJson(data) {
// ensure the existence of the libs section in the dependencies
Expand All @@ -42,24 +46,44 @@ module.exports = function({workspace, options}) {
}

async function updateFLdependency() {
const manifestResource = await workspace.byPath(`${pathPrefix}/manifest.json`);
codeworrior marked this conversation as resolved.
Show resolved Hide resolved
const manifestContent = JSON.parse(await manifestResource.getString());

updateJson(manifestContent);
manifestResource.setString(JSON.stringify(manifestContent, null, "\t"));

await workspace.write(manifestResource);
}

async function readManifestMinUI5Version() {
return workspace.byPath(`${pathPrefix}/manifest.json`).then((manifestResourceResult) => {
manifestResource = manifestResourceResult;
if (manifestResource) {
return manifestResource.getBuffer().then((buffer) => {
return JSON.parse(buffer.toString());
});
}
return {};
}).then((manifestContentResult) => {
manifestContent = Object.assign({}, manifestContentResult);
manifestContentResult["sap.ui5"] = manifestContentResult["sap.ui5"] || {};
manifestContentResult["sap.ui5"].dependencies = manifestContentResult["sap.ui5"].dependencies || {};
return manifestContentResult["sap.ui5"].dependencies.minUI5Version = manifestContentResult["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: {
pathPrefix,
hasFlexBundleVersion
}
});
});
})
.then((processedResources) => {
Expand Down

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

3 changes: 2 additions & 1 deletion test/expected/build/application.i/dest/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"sap.ui.core": {},
"sap.m": {},
"sap.ui.fl": {}
}
},
"minUI5Version": "1.72.0"
}
}
}
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
3 changes: 2 additions & 1 deletion test/fixtures/application.i/webapp/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"sap.ui.layout": {},
"sap.ui.core": {},
"sap.m": {}
}
},
"minUI5Version": "1.72.0"
}
}
}
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
}
Loading