Skip to content

Commit

Permalink
[INTERNAL][WIP] VersionInfo: with manifest infos
Browse files Browse the repository at this point in the history
improved test
sort keys of objects
  • Loading branch information
tobiasso85 committed Dec 2, 2020
1 parent 7618c57 commit d2e32e8
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 258 deletions.
115 changes: 67 additions & 48 deletions lib/processors/versionInfoGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ const resolve = (libName, libraryInfosMap, resolvedCache) => {
let resolved = manifestHint;
if (!manifestHint) {
log.error(`no manifest information in dependencies for ${libName}`);
resolvedCache.set(libName, resolved);
return resolved;
resolvedCache.set(libName, {});
return {};
}
const keys = Object.keys(manifestHint);
keys.forEach((childLibName) => {
Expand All @@ -173,6 +173,56 @@ const resolve = (libName, libraryInfosMap, resolvedCache) => {
return resolved;
};

/**
* Sorts the keys of a given object
*
* @param {object} obj the object
* @returns {{}}
*/
const sortObjectKeys = (obj) => {
const sortedObject = {};
const keys = Object.keys(obj);
keys.sort();
keys.forEach((key) => {
sortedObject[key] = obj[key];
});
return sortedObject;
};

const addManifestHints = (result, libs) => {
if (Object.keys(libs).length) {
const sortedLibs = sortObjectKeys(libs);
result.manifestHints = {
dependencies: {
libs: sortedLibs
}
};
}
};

const processLibraryInfo = async (libraryInfo, dependencyInfoMap, embeddedInfoMap) => {
const manifestInfo = await processManifest(libraryInfo.mainManifest);
dependencyInfoMap.set(libraryInfo.name, manifestInfo.libs);
const embeds = manifestInfo.embeds;
// filter
const embeddedPaths = embeds.map((embed) => {
return getManifestPath(libraryInfo.mainManifest.getPath(), embed);
});
const relevantManifests = libraryInfo.manifestResources.filter((manifestResource) => {
return embeddedPaths.includes(manifestResource.getPath());
});

// get all embedded manifests
const embeddedManifestPromises = relevantManifests.map(async (relevantManifest) => {
const result = await processManifest(relevantManifest);
dependencyInfoMap.set(result.id, result.libs);
embeddedInfoMap.set(result.id, {
library: libraryInfo.name
});
});

await Promise.all(embeddedManifestPromises);
};

/**
* Creates sap-ui-version.json.
Expand All @@ -183,8 +233,8 @@ const resolve = (libName, libraryInfosMap, resolvedCache) => {
* @param {object} parameters.options Options
* @param {string} parameters.options.rootProjectName Name of the root project
* @param {string} parameters.options.rootProjectVersion Version of the root project
* @param {Array} parameters.options.libraryInfos Array of objects representing libraries,
* e.g. <code>{name: "library.xy", version: "1.0.0"}</code>
* @param {LibraryInfo[]} parameters.options.libraryInfos Array of objects representing libraries,
* e.g. <code>{name: "library.xy", version: "1.0.0", manifests: module:@ui5/fs.Resource[]}</code>
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving with an array containing the versioninfo resource
*/

Expand All @@ -198,11 +248,13 @@ module.exports = async function({options}) {
const components = {};
/**
* @example
* "sap.ui.integration": {
* sap.chart: {
* lazy: true
* },
* sap.f: { },
* {
* "sap.ui.integration": {
* "sap.chart": {
* "lazy": true
* },
* "sap.f": { },
* }
* }
*
* @type {Map<string, DependencyInfos>}
Expand All @@ -212,29 +264,7 @@ module.exports = async function({options}) {

// gather all manifestHints
const librariesPromises = options.libraryInfos.map((libraryInfo) => {
// TODO use proper async await!
return processManifest(libraryInfo.mainManifest).then((manifestHint) => {
dependencyInfoMap.set(libraryInfo.name, manifestHint.libs);
return manifestHint.embeds;
}).then((embeds) => {
// filter
const embeddedPaths = embeds.map((embed) => {
return getManifestPath(libraryInfo.mainManifest.getPath(), embed);
});
const relevantManifests = libraryInfo.manifestResources.filter((manifestResource) => {
return embeddedPaths.includes(manifestResource.getPath());
});

// get all embedded manifests
return Promise.all(relevantManifests.map((relevantManifest) => {
return processManifest(relevantManifest).then((result) => {
dependencyInfoMap.set(result.id, result.libs);
embeddedInfoMap.set(result.id, {
library: libraryInfo.name
});
});
}));
});
return processLibraryInfo(libraryInfo, dependencyInfoMap, embeddedInfoMap);
});

await Promise.all(librariesPromises);
Expand All @@ -252,28 +282,17 @@ module.exports = async function({options}) {
};

const libs = dependencyInfoMap.get(libraryInfo.name);
if (Object.keys(libs).length) {
result.manifestHints = {
dependencies: {
libs: libs
}
};
}
addManifestHints(result, libs);
return result;
});

// TODO sort!
// sort keys
embeddedInfoMap.forEach((embeddedInfo, libName) => {
components[libName] = embeddedInfo;
const libs = dependencyInfoMap.get(libName);
if (libs && Object.keys(libs).length) {
components[libName].manifestHints = {
dependencies: {
libs: libs
}
};
}
addManifestHints(components[libName], libs);
});
const sortedComponents = sortObjectKeys(components);

// sort libraries alphabetically
libraries.sort((a, b) => {
Expand All @@ -287,7 +306,7 @@ module.exports = async function({options}) {
scmRevision: "", // TODO: insert current application scm revision here
// gav: "", // TODO: insert current application id + version here
libraries,
components
components: sortedComponents
};

return [resourceFactory.createResource({
Expand Down
16 changes: 3 additions & 13 deletions lib/tasks/generateVersionInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,16 @@ const MANIFEST_JSON = "manifest.json";
* @param {module:@ui5/fs.AbstractReader} parameters.dependencies Reader or Collection to read dependency files
* @param {object} parameters.options Options
* @param {string} parameters.options.pattern Glob pattern for .library resources
* @param {string} parameters.options.namespace Namespace of the project
* @param {object} parameters.options.rootProject DuplexCollection to read and write files
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
*/
module.exports = async ({workspace, dependencies, options: {rootProject, pattern, namespace}}) => {
module.exports = async ({workspace, dependencies, options: {rootProject, pattern}}) => {
const resources = await dependencies.byGlob(pattern);

// app always builds all dependencies -> therefore glob all manifest.json
// build with --all should not use the version-info.json
// logic needs to be adjusted once selective dependencies are built
// TODO: transient resources (not part of the build result) ( -> skipped for now)
// exclude task if not build --all

const libraryInfosPromises = resources.map((dotLibResource) => {
const namespace = dotLibResource._project.metadata.namespace;
// TODO favor manifest.json over .library (check first manifest.json then as fallback .library)
// long-term goal: get rid of .library files
// TODO: compare the two
// use /**/ for nested manifests
// use /sap.app/embeds
// pass all required resources to the processor
// the processor will then filter
return dependencies.byGlob(`/resources/${namespace}/**/${MANIFEST_JSON}`).then((manifestResources) => {
const mainManifest = manifestResources.find((manifestResource) => {
return manifestResource.getPath() === `/resources/${namespace}/${MANIFEST_JSON}`;
Expand Down
Loading

0 comments on commit d2e32e8

Please sign in to comment.