From e346f0c4bba0f99c1cd1912886571b47bc410bdc Mon Sep 17 00:00:00 2001 From: Tobias Sorn Date: Mon, 4 Jan 2021 15:18:04 +0100 Subject: [PATCH] [FEATURE] manifestCreator: i18n section v22 Rename types to avoid confusion --- lib/processors/versionInfoGenerator.js | 62 ++++++++++++++++---------- lib/tasks/generateVersionInfo.js | 4 +- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/lib/processors/versionInfoGenerator.js b/lib/processors/versionInfoGenerator.js index 9a813d68f..c3705b0a5 100644 --- a/lib/processors/versionInfoGenerator.js +++ b/lib/processors/versionInfoGenerator.js @@ -20,7 +20,7 @@ function getTimestamp() { /** * * @param {module:@ui5/fs.Resource} manifestResource - * @returns {Promise} + * @returns {Promise} */ const processManifest = async (manifestResource) => { const manifestContent = await manifestResource.getString(); @@ -58,7 +58,7 @@ const processManifest = async (manifestResource) => { /** * Library Info * - * @typedef {object} DependencyInfos + * @typedef {object} ManifestLibs * * * @example * { @@ -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" * @@ -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 */ @@ -112,15 +114,16 @@ const getManifestPath = (filePath, subPath) => { }; /** + * Resolves the dependencies recursively * - * @param {Map} libraryInfosMap + * @param {Map} 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); }); }; @@ -128,7 +131,7 @@ 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; @@ -146,11 +149,6 @@ class DependencyInfo { this.libs = libs; this.name = name; - /** - * - * @type {string[]} - */ - this.resolved = []; /** * * @type {DependencyInfoObject[]} @@ -190,7 +188,8 @@ class DependencyInfo { /** * * @param {Map} 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) { @@ -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] = {}; @@ -261,19 +259,27 @@ const convertToDependencyInfoObjects = (libs) => { }); }; +/** + * Processes the library info and fills the maps dependencyInfoMap and embeddedInfoMap. + * + * @param {LibraryInfo} libraryInfo + * @param {Map} dependencyInfoMap + * @param {Map} embeddedInfoMap + * @returns {Promise} + */ 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) => { @@ -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[] * } * @@ -336,6 +342,15 @@ module.exports = async function({options}) { * @type {Map} */ const dependencyInfoMap = new Map(); + /** + * @example + * { + * "sap.ui.integration.sdk": { + * "library": "sap.ui.integration" + * } + * + * @type {Map} + */ const embeddedInfoMap = new Map(); // gather all manifestHints @@ -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); diff --git a/lib/tasks/generateVersionInfo.js b/lib/tasks/generateVersionInfo.js index a29b70fdd..73f7b8536 100644 --- a/lib/tasks/generateVersionInfo.js +++ b/lib/tasks/generateVersionInfo.js @@ -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