Skip to content

Commit

Permalink
[INTERNAL] change comment and change read manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
thuyboehm committed Nov 7, 2019
1 parent 3f30fd0 commit 7d77213
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 35 deletions.
2 changes: 1 addition & 1 deletion lib/processors/bundlers/flexChangesBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = function({resources, options}) {
});

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");
throw new Error("There are 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) {
Expand Down
52 changes: 24 additions & 28 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 control variants and minUI5Version < 1.73 build will break and throw an error.
* If there are control variants and minUI5Version < 1.73 build will break and throw an error.
*
* @public
* @alias module:@ui5/builder.tasks.generateFlexChangesBundle
Expand All @@ -24,8 +24,6 @@ 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 @@ -46,45 +44,43 @@ 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);
}

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 || "";
});
const manifestResource = await workspace.byPath(`${pathPrefix}/manifest.json`);
const manifestContent = JSON.parse(await manifestResource.getString());

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,variant,ctrl_variant,ctrl_variant_change,ctrl_variant_management_change}`)
.then((allResources) => {
return readManifestMinUI5Version().then((version) => {
let hasFlexBundleVersion = false;
if (parseFloat(version) >= 1.73) {
hasFlexBundleVersion = true;
}
return flexChangesBundler({
resources: allResources,
options: {
pathPrefix,
hasFlexBundleVersion
if (allResources.length > 0) {
return readManifestMinUI5Version().then((version) => {
let hasFlexBundleVersion = false;
if (parseFloat(version) >= 1.73) {
hasFlexBundleVersion = true;
}
return flexChangesBundler({
resources: allResources,
options: {
pathPrefix,
hasFlexBundleVersion
}
});
});
});
}
return [];
})
.then((processedResources) => {
return Promise.all(processedResources.map((resource) => {
Expand Down

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

3 changes: 1 addition & 2 deletions test/expected/build/application.i/dest/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"sap.ui.core": {},
"sap.m": {},
"sap.ui.fl": {}
},
"minUI5Version": "1.72.0"
}
}
}
}
3 changes: 1 addition & 2 deletions test/fixtures/application.i/webapp/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"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 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");
t.deepEqual(error.message, "There are 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 7d77213

Please sign in to comment.