Skip to content

Commit

Permalink
[INTERNAL][FIX] Fix of the flexChangesBundler.js to sort correctly (#198
Browse files Browse the repository at this point in the history
)

The flexChangesBundler used the wrong operation to sort the files
contained in the /changes/ folder of an application. Thus the sorting
may be incorrect.
This commit changes the operator to sort accordingly.
  • Loading branch information
Lonwyr authored and devtomtom committed Jun 17, 2019
1 parent 56d3433 commit 81e29f0
Show file tree
Hide file tree
Showing 22 changed files with 304 additions and 99 deletions.
22 changes: 4 additions & 18 deletions lib/processors/bundlers/flexChangesBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,15 @@ 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
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving with flexchange bundle resources
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving with flex changes bundle resources
*/
module.exports = function({resources, options}) {
const layers = {
VENDOR: 0,
INDUSTRY: 1,
PARTNER: 2,
CUSTOMER_BASE: 3,
CUSTOMER: 4,
USER: 5
};

function sortByLayer(a, b) {
return layers[a.layer] - layers[b.layer];
}

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

function sortAndStringify(changesContent) {
changesContent = changesContent.sort(sortByTimeStamp);
changesContent = changesContent.sort(sortByLayer);
changesContent = changesContent.map(function(change) {
return JSON.stringify(change);
});
Expand All @@ -45,13 +31,13 @@ module.exports = function({resources, options}) {
});
})).then((changesContent) => {
const nNumberOfChanges = changesContent.length;
log.verbose("Changes collected. Number of changes: " + nNumberOfChanges);
log.info("Changes collected. Number of changes: " + nNumberOfChanges);
const result = [];
if (nNumberOfChanges > 0) {
changesContent = sortAndStringify(changesContent);
result.push(resourceFactory.createResource({
path: `${options.pathPrefix}/changes/changes-bundle.json`,
string: "{ \"changes\": [" + changesContent.join(",") + "]}"
string: "[" + changesContent.join(",") + "]"
}));
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion test/expected/build/application.h/dest/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"_version": "1.1.0",
"sap.app": {
"_version": "1.1.0",
"id": "application.g",
"id": "application.h",
"type": "application",
"applicationVersion": {
"version": "1.2.2"
Expand Down
11 changes: 11 additions & 0 deletions test/expected/build/application.i/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.i/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 @@
[{"fileName":"id_456_addField","fileType":"change","changeType":"hideControl","component":"application.i.Component","content":{},"selector":{"id":"control1"},"layer":"VENDOR","texts":{},"namespace":"apps/application.i.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.i.Component","content":{},"selector":{"id":"control1"},"layer":"VENDOR","texts":{},"namespace":"apps/application.i.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 @@
sap.ui.define([],function(){return{}});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<xml>

</xml>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"fileName": "id_123_addField",
"fileType": "change",
"changeType": "hideControl",
"component": "application.i.Component",
"content": {},
"selector": {
"id": "control1"
},
"layer": "VENDOR",
"texts": {},
"namespace": "apps/application.i.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_456_addField",
"fileType": "change",
"changeType": "hideControl",
"component": "application.i.Component",
"content": {},
"selector": {
"id": "control1"
},
"layer": "VENDOR",
"texts": {},
"namespace": "apps/application.i.Component/changes",
"creation": "2023-10-30T13:52:40.4754350Z",
"originalLanguage": "",
"conditions": {},
"support": {
"generator": "did it",
"user": "Max Mustermann"
}
}
13 changes: 13 additions & 0 deletions test/expected/build/application.i/dest/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"_version": "1.1.0",
"sap.app": {
"_version": "1.1.0",
"id": "application.i",
"type": "application",
"applicationVersion": {
"version": "1.2.2"
},
"embeds": ["embedded"],
"title": "{{title}}"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/application.h/ui5.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
specVersion: "0.1"
type: application
metadata:
name: application.g
name: application.h
builder:
bundles:
- name: sap/ushell/bootstrap/cdm.js
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/application.h/webapp/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"_version": "1.1.0",
"sap.app": {
"_version": "1.1.0",
"id": "application.g",
"id": "application.h",
"type": "application",
"applicationVersion": {
"version": "1.2.2"
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/application.i/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "application.i",
"version": "1.0.0",
"description": "Simple SAPUI5 based application",
"main": "index.html",
"dependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
}
25 changes: 25 additions & 0 deletions test/fixtures/application.i/ui5.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
specVersion: "0.1"
type: application
metadata:
name: application.i
builder:
bundles:
- name: sap/ushell/bootstrap/cdm.js
defaultFileTypes:
- ".js"
sections:
- mode: raw
filters:
- ui5loader.js
- ui5loader-autoconfig.js
declareModules: false
resolve: true
- mode: preload
name: sap/ushell/bootstrap/common
filters:
- sap/ushell/bootstrap/cdm/cdm-def.js
resolve: true
- mode: require
filters:
- sap/ushell/bootstrap/cdm/cdm-def.js
8 changes: 8 additions & 0 deletions test/fixtures/application.i/webapp/Component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent){
"use strict";
return UIComponent.extend('application.i.Component', {
metadata: {
manifest: "json"
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sap.ui.define([],function () {
return {};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<xml>

</xml>
20 changes: 20 additions & 0 deletions test/fixtures/application.i/webapp/changes/id_123_addField.change
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"fileName": "id_123_addField",
"fileType": "change",
"changeType": "hideControl",
"component": "application.i.Component",
"content": {},
"selector": {
"id": "control1"
},
"layer": "VENDOR",
"texts": {},
"namespace": "apps/application.i.Component/changes",
"creation": "2025-10-30T13:52:40.4754350Z",
"originalLanguage": "",
"conditions": {},
"support": {
"generator": "did it",
"user": "Max Mustermann"
}
}
20 changes: 20 additions & 0 deletions test/fixtures/application.i/webapp/changes/id_456_addField.change
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"fileName": "id_456_addField",
"fileType": "change",
"changeType": "hideControl",
"component": "application.i.Component",
"content": {},
"selector": {
"id": "control1"
},
"layer": "VENDOR",
"texts": {},
"namespace": "apps/application.i.Component/changes",
"creation": "2023-10-30T13:52:40.4754350Z",
"originalLanguage": "",
"conditions": {},
"support": {
"generator": "did it",
"user": "Max Mustermann"
}
}
13 changes: 13 additions & 0 deletions test/fixtures/application.i/webapp/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"_version": "1.1.0",
"sap.app": {
"_version": "1.1.0",
"id": "application.i",
"type": "application",
"applicationVersion": {
"version": "1.2.2"
},
"embeds": ["embedded"],
"title": "{{title}}"
}
}
48 changes: 48 additions & 0 deletions test/lib/builder/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const builder = ui5Builder.builder;
const applicationAPath = path.join(__dirname, "..", "..", "fixtures", "application.a");
const applicationGPath = path.join(__dirname, "..", "..", "fixtures", "application.g");
const applicationHPath = path.join(__dirname, "..", "..", "fixtures", "application.h");
const applicationIPath = path.join(__dirname, "..", "..", "fixtures", "application.i");
const libraryDPath = path.join(__dirname, "..", "..", "fixtures", "library.d");
const libraryEPath = path.join(__dirname, "..", "..", "fixtures", "library.e");
const libraryHPath = path.join(__dirname, "..", "..", "fixtures", "library.h");
Expand Down Expand Up @@ -171,6 +172,26 @@ test("Build application.h", (t) => {
});
});

test("Build application.i", (t) => {
const destPath = "./test/tmp/build/application.i/dest";
const expectedPath = path.join("test", "expected", "build", "application.i", "dest");

return builder.build({
tree: applicationITree,
destPath,
excludedTasks: ["createDebugFiles", "generateStandaloneAppBundle", "generateVersionInfo"]
}).then(() => {
return findFiles(expectedPath);
}).then((expectedFiles) => {
// Check for all directories and files
assert.directoryDeepEqual(destPath, expectedPath);
// Check for all file contents
return checkFileContentsIgnoreLineFeeds(expectedFiles, expectedPath, destPath);
}).then(() => {
t.pass();
});
});

test("Build library.d with copyright from .library file", (t) => {
const destPath = "./test/tmp/build/library.d/dest";
const expectedPath = path.join("test", "expected", "build", "library.d", "dest");
Expand Down Expand Up @@ -549,6 +570,33 @@ const applicationHTree = {
}
};

const applicationITree = {
"id": "application.i",
"version": "1.0.0",
"path": applicationIPath,
"_level": 0,
"specVersion": "0.1",
"type": "application",
"metadata": {
"name": "application.i",
"namespace": "application/i"
},
"dependencies": [],
"resources": {
"configuration": {
"paths": {
"webapp": "webapp"
}
},
"pathMappings": {
"/": "webapp"
}
},
"builder": {
"bundles": []
}
};

const libraryDTree = {
"id": "library.d",
"version": "1.0.0",
Expand Down
Loading

0 comments on commit 81e29f0

Please sign in to comment.