Skip to content

Commit

Permalink
[INTERNAL] change comment, optimize some lines
Browse files Browse the repository at this point in the history
  • Loading branch information
thuyboehm committed Nov 4, 2019
1 parent 3b9acc9 commit 3f30fd0
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 40 deletions.
53 changes: 30 additions & 23 deletions lib/processors/bundlers/flexChangesBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ module.exports = function({resources, options}) {
return a.creation > b.creation ? 1 : -1;
}

/**
* 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) {
changesContent = changesContent.sort(sortByTimeStamp);
const changeList = [];
const variantDependentControlChangeList = [];
const compVariantList = [];
const variantList = [];
const variantChangeList = [];
const variantManagementChangeList = [];
const changes = [];
const variantDependentControlChanges = [];
const compVariants = [];
const variants = [];
const variantChanges = [];
const variantManagementChanges = [];

changesContent.forEach(function(content) {
switch (content.fileType) {
Expand All @@ -36,41 +42,42 @@ module.exports = function({resources, options}) {
break;
}
if (content.variantReference && content.variantReference !== "") {
variantDependentControlChangeList.push(content);
variantDependentControlChanges.push(content);
} else {
changeList.push(content);
changes.push(content);
}
break;
case "variant":
compVariantList.push(content);
compVariants.push(content);
break;
case "ctrl_variant":
variantList.push(content);
variants.push(content);
break;
case "ctrl_variant_change":
variantChangeList.push(content);
variantChanges.push(content);
break;
case "ctrl_variant_management_change":
variantManagementChangeList.push(content);
variantManagementChanges.push(content);
break;
}
});

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");
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");
}
// create changes-bundle.json
if (!options.hasFlexBundleVersion) {
return JSON.stringify(changeList);
return JSON.stringify(changes);
} else {
bundleName = "flexibility-bundle.json";
const newChangeFormat = {};
newChangeFormat.changes = changeList;
newChangeFormat.compVariants = compVariantList;
newChangeFormat.variants = variantList;
newChangeFormat.variantChanges = variantChangeList;
newChangeFormat.variantDependentControlChanges = variantDependentControlChangeList;
newChangeFormat.variantManagementChanges = variantManagementChangeList;
const newChangeFormat = {
changes,
compVariants,
variants,
variantChanges,
variantDependentControlChanges,
variantManagementChanges
};

return JSON.stringify(newChangeFormat);
}
Expand All @@ -87,7 +94,7 @@ module.exports = function({resources, options}) {
if (nNumberOfChanges > 0) {
changesContent = sortAndStringifyInFlexFormat(changesContent);
result.push(resourceFactory.createResource({
path: `${options.pathPrefix}/changes/` + bundleName,
path: `${options.pathPrefix}/changes/${bundleName}`,
string: changesContent
}));
}
Expand Down
26 changes: 13 additions & 13 deletions lib/tasks/bundlers/generateFlexChangesBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const flexChangesBundler = require("../../processors/bundlers/flexChangesBundler
* 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.
* If there a control variants and minUI5Version < 1.73 build will break and throw an error.
*
* @public
* @alias module:@ui5/builder.tasks.generateFlexChangesBundle
Expand All @@ -24,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 @@ -44,27 +46,26 @@ module.exports = function({workspace, options}) {
}

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

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

await workspace.write(manifestResource);
}

function readManifestMinUI5Version() {
return workspace.byPath(`${pathPrefix}/manifest.json`).then((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((manifestContent) => {
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 || "";
}).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 || "";
});
}

Expand All @@ -79,9 +80,8 @@ module.exports = function({workspace, options}) {
return flexChangesBundler({
resources: allResources,
options: {
namespace: options.namespace,
pathPrefix: pathPrefix,
hasFlexBundleVersion: hasFlexBundleVersion
pathPrefix,
hasFlexBundleVersion
}
});
});
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"
}
}
}
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"
}
}
}
2 changes: 1 addition & 1 deletion test/lib/processors/bundlers/flexChangesBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,5 @@ test("flexChangesBundler has ctrl_variant and hasFlexBundleVersion = false", asy
};

const error = await t.throwsAsync(flexChangesBundler({resources, options}), Error);
t.deepEqual(error.message, "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", "Correct exception thrown");
t.deepEqual(error.message, "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", "Correct exception thrown");
});

0 comments on commit 3f30fd0

Please sign in to comment.