Skip to content

Commit

Permalink
fix jsdoc example
Browse files Browse the repository at this point in the history
use typedef instead of own class for a data container

do embedded component dependencies resolving after library
dependencies resolving in separate step to avoid mixing them up.
  • Loading branch information
tobiasso85 committed Jan 14, 2021
1 parent 2526ebd commit 1fe9c25
Showing 1 changed file with 24 additions and 64 deletions.
88 changes: 24 additions & 64 deletions lib/processors/versionInfoGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function getTimestamp() {
*
* @typedef {object<string, object>} ManifestLibraries
*
* * @example
* @example
* {
* sap.chart: {
* lazy: true
Expand All @@ -32,49 +32,15 @@ function getTimestamp() {

/**
* Extracted information from a manifest's <code>sap.app</code> and <code>sap.ui5</code> sections.
*
* @typedef {object} ManifestInfo
*
* @property {string} id The library name
* @property {string} embeddedBy the library this component is embedded in
* @property {string[]} embeds the embedded component names
* @property {ManifestLibraries} libs the dependencies
*/
class ManifestInfo {
constructor() {
this.libs = {};
this.embeds = [];
}

/**
* The library object
*
* @param {ManifestLibraries} libs
*/
setLibs(libs) {
this.libs = libs;
}

/**
* embedded components, e.g. ["sub/fold"] (relative paths)
*
* @param {string[]} embeds
*/
setEmbeds(embeds) {
this.embeds = embeds;
}

/**
* relative path to the component which embeds this component, e.g. "../"
*
* @param {string} embeddedBy
*/
setEmbeddedBy(embeddedBy) {
this.embeddedBy = embeddedBy;
}

/**
* the app id, e.g. "sap.x"
*
* @param {string} id
*/
setId(id) {
this.id = id;
}
}

/**
* Processes manifest resource and extracts information.
Expand All @@ -85,7 +51,7 @@ class ManifestInfo {
const processManifest = async (manifestResource) => {
const manifestContent = await manifestResource.getString();
const manifestObject = JSON.parse(manifestContent);
const manifestInfo = new ManifestInfo();
const manifestInfo = {};

// sap.ui5/dependencies is used for the "manifestHints/libs"
if (manifestObject["sap.ui5"]) {
Expand All @@ -98,20 +64,20 @@ const processManifest = async (manifestResource) => {
libs[libKey].lazy = true;
}
});
manifestInfo.setLibs(libs);
manifestInfo.libs = libs;
}
}

// sap.app/embeds, sap.app/embeddedBy and sap.app/id is used for "components"
if (manifestObject["sap.app"]) {
const manifestEmbeds = manifestObject["sap.app"]["embeds"];
manifestInfo.setEmbeds(manifestEmbeds);
manifestInfo.embeds = manifestEmbeds;

const manifestEmbeddedBy = manifestObject["sap.app"]["embeddedBy"];
manifestInfo.setEmbeddedBy(manifestEmbeddedBy);
manifestInfo.embeddedBy = manifestEmbeddedBy;

const id = manifestObject["sap.app"]["id"];
manifestInfo.setId(id);
manifestInfo.id = id;
}
return manifestInfo;
};
Expand Down Expand Up @@ -169,17 +135,6 @@ const getManifestPath = (filePath, subPath) => {
return posixPath.resolve(folderPathOfManifest + "/manifest.json");
};

/**
* Resolves the transitive dependencies recursively.
*
* @param {Map<string, DependencyInfo>} dependencyInfoMap
*/
const resolveTransitiveDependencies = (dependencyInfoMap) => {
dependencyInfoMap.forEach((libraryInfo) => {
libraryInfo.resolve(dependencyInfoMap);
});
};

class DependencyInfoObject {
/**
*
Expand Down Expand Up @@ -481,14 +436,19 @@ module.exports = async function({options}) {
// fill dependencyInfoMap
artifactInfos.forEach((artifactInfo) => {
dependencyInfoMap.set(artifactInfo.componentName, artifactInfo.dependencyInfo);
artifactInfo.getEmbeds().forEach((embeddedArtifactInfo) => {
dependencyInfoMap.set(embeddedArtifactInfo.componentName, embeddedArtifactInfo.dependencyInfo);
});
});

// resolve nested dependencies (transitive)
resolveTransitiveDependencies(dependencyInfoMap);
// resolve library dependencies (transitive)
dependencyInfoMap.forEach((dependencyInfo) => {
dependencyInfo.resolve(dependencyInfoMap);
});

// resolve dependencies of embedded components
artifactInfos.forEach((artifactInfo) => {
artifactInfo.getEmbeds().forEach((embeddedArtifactInfo) => {
embeddedArtifactInfo.dependencyInfo.resolve(dependencyInfoMap);
});
});

const libraries = options.libraryInfos.map((libraryInfo) => {
const result = {
Expand Down Expand Up @@ -519,7 +479,7 @@ module.exports = async function({options}) {
library: embeddedArtifactInfo.parentComponentName
};
const componentName = embeddedArtifactInfo.componentName;
const dependencyInfo = dependencyInfoMap.get(componentName);
const dependencyInfo = embeddedArtifactInfo.dependencyInfo;
const manifestHints = getManifestHints(dependencyInfo);
if (manifestHints) {
componentObject.manifestHints = manifestHints;
Expand Down

0 comments on commit 1fe9c25

Please sign in to comment.