Skip to content

Commit

Permalink
[FEATURE] manifestCreator: i18n section v22
Browse files Browse the repository at this point in the history
Rename types to avoid confusion
  • Loading branch information
tobiasso85 committed Jan 4, 2021
1 parent 8cbb2ca commit e346f0c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
62 changes: 38 additions & 24 deletions lib/processors/versionInfoGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function getTimestamp() {
/**
*
* @param {module:@ui5/fs.Resource} manifestResource
* @returns {Promise<ManifestInfos>}
* @returns {Promise<ManifestInfo>}
*/
const processManifest = async (manifestResource) => {
const manifestContent = await manifestResource.getString();
Expand Down Expand Up @@ -58,7 +58,7 @@ const processManifest = async (manifestResource) => {
/**
* Library Info
*
* @typedef {object<string, object>} DependencyInfos
* @typedef {object<string, object>} ManifestLibs
*
* * @example
* {
Expand All @@ -72,8 +72,8 @@ const processManifest = async (manifestResource) => {
/**
* Manifest Hint
*
* @typedef {object} ManifestInfos
* @property {DependencyInfos} libs The library object
* @typedef {object} ManifestInfo
* @property {ManifestLibs} libs The library object
* @property {string[]} embeds embedded components, e.g. "sub/fold" (only relative path)
* @property {string} id the app id, e.g. "lib.a"
*
Expand All @@ -94,12 +94,14 @@ const processManifest = async (manifestResource) => {


/**
* Library Info object
* Library Info
*
* contains information about the name the version of the library and its manifest, as well as the nested manifests.
*
* @typedef {object} LibraryInfo
* @property {string} name The library name
* @property {string} version The library version
* @property {module:@ui5/fs.Resource} mainManifest main manifest resources
* @property {module:@ui5/fs.Resource} libraryManifest main manifest resources
* @property {module:@ui5/fs.Resource[]} manifestResources list of corresponding manifest resources
*/

Expand All @@ -112,23 +114,24 @@ const getManifestPath = (filePath, subPath) => {
};

/**
* Resolves the dependencies recursively
*
* @param {Map<string, DependencyInfos>} libraryInfosMap
* @param {Map<string, DependencyInfo>} dependencyInfoMap
*/
const resolveTransitiveDependencies = (libraryInfosMap) => {
const keys = [...libraryInfosMap.keys()];
const resolveTransitiveDependencies = (dependencyInfoMap) => {
const keys = [...dependencyInfoMap.keys()];
keys.sort();
keys.forEach((libName) => { // e.g. sap.ui.documentation
const libraryInfo = libraryInfosMap.get(libName);
libraryInfo.resolve(libraryInfosMap);
const libraryInfo = dependencyInfoMap.get(libName);
libraryInfo.resolve(dependencyInfoMap);
});
};

class DependencyInfoObject {
/**
*
* @param {string} name name of the dependency, e.g. sap.ui.documentation
* @param {boolean} lazy
* @param {boolean} lazy lazy dependency
*/
constructor(name, lazy) {
this.name = name;
Expand All @@ -146,11 +149,6 @@ class DependencyInfo {
this.libs = libs;
this.name = name;

/**
*
* @type {string[]}
*/
this.resolved = [];
/**
*
* @type {DependencyInfoObject[]}
Expand Down Expand Up @@ -190,7 +188,8 @@ class DependencyInfo {
/**
*
* @param {Map<string,DependencyInfo>} dependencyInfoMap
* @param {boolean} [lazy]
* @param {boolean} [lazy] whether or not the dependency is lazy dependency which means
* all its dependencies should be treated as lazy
*/
resolve(dependencyInfoMap, lazy) {
if (!this.wasResolved || lazy) {
Expand Down Expand Up @@ -238,7 +237,6 @@ const sortObjectKeys = (obj) => {
*/
const addManifestHints = (result, dependencyInfo) => {
if (dependencyInfo && dependencyInfo.libs.length) {
// const sortedLibs = sortObjectKeys(libs.libs);
const libsObject = {};
dependencyInfo.libsResolved.forEach((sortedLib) => {
libsObject[sortedLib.name] = {};
Expand All @@ -261,19 +259,27 @@ const convertToDependencyInfoObjects = (libs) => {
});
};

/**
* Processes the library info and fills the maps <code>dependencyInfoMap</code> and <code>embeddedInfoMap</code>.
*
* @param {LibraryInfo} libraryInfo
* @param {Map<string, DependencyInfo>} dependencyInfoMap
* @param {Map<string, object>} embeddedInfoMap
* @returns {Promise<void>}
*/
const processLibraryInfo = async (libraryInfo, dependencyInfoMap, embeddedInfoMap) => {
if (!libraryInfo.mainManifest) {
if (!libraryInfo.libraryManifest) {
log.error(`library manifest not found for ${libraryInfo.name}`);
return;
}
const manifestInfo = await processManifest(libraryInfo.mainManifest);
const manifestInfo = await processManifest(libraryInfo.libraryManifest);
// gather shallow library information
const dependencyInfoObjects = convertToDependencyInfoObjects(manifestInfo.libs);
dependencyInfoMap.set(libraryInfo.name, new DependencyInfo(dependencyInfoObjects, libraryInfo.name));
const embeds = manifestInfo.embeds; // sdk
// filter
const embeddedPaths = embeds.map((embed) => {
return getManifestPath(libraryInfo.mainManifest.getPath(), embed);
return getManifestPath(libraryInfo.libraryManifest.getPath(), embed);
});
// sap.ui.documentation.sdk
const relevantManifests = libraryInfo.manifestResources.filter((manifestResource) => {
Expand Down Expand Up @@ -307,7 +313,7 @@ const processLibraryInfo = async (libraryInfo, dependencyInfoMap, embeddedInfoMa
* {
* name: "library.xy",
* version: "1.0.0",
* mainManifest: module:@ui5/fs.Resource,
* libraryManifest: module:@ui5/fs.Resource,
* manifestResources: module:@ui5/fs.Resource[]
* }
* </code>
Expand Down Expand Up @@ -336,6 +342,15 @@ module.exports = async function({options}) {
* @type {Map<string, DependencyInfo>}
*/
const dependencyInfoMap = new Map();
/**
* @example
* {
* "sap.ui.integration.sdk": {
* "library": "sap.ui.integration"
* }
*
* @type {Map<string, object>}
*/
const embeddedInfoMap = new Map();

// gather all manifestHints
Expand All @@ -362,7 +377,6 @@ module.exports = async function({options}) {
return result;
});

// sort keys
embeddedInfoMap.forEach((embeddedInfo, libName) => {
components[libName] = embeddedInfo;
const libs = dependencyInfoMap.get(libName);
Expand Down
4 changes: 2 additions & 2 deletions lib/tasks/generateVersionInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ module.exports = async ({workspace, dependencies, options: {rootProject, pattern
// 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) => {
const libraryManifest = manifestResources.find((manifestResource) => {
return manifestResource.getPath() === `/resources/${namespace}/${MANIFEST_JSON}`;
});
return {
mainManifest, // TODO rename libraryManifest
libraryManifest,
manifestResources,
name: dotLibResource._project.metadata.name,
version: dotLibResource._project.version
Expand Down

0 comments on commit e346f0c

Please sign in to comment.