Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Enhance versionInfo middleware to serve sap-ui-version.json #420

Merged
merged 4 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 56 additions & 29 deletions lib/middleware/versionInfo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const createVersionInfoProcessor = require("@ui5/builder").processors.versionInfoGenerator;
const createManifestProcessor = require("@ui5/builder").processors.manifestCreator;

const MANIFEST_JSON = "manifest.json";

/**
* Creates and returns the middleware to create the version info as json object.
Expand All @@ -10,37 +13,61 @@ const createVersionInfoProcessor = require("@ui5/builder").processors.versionInf
* @returns {Function} Returns a server middleware closure.
*/
function createMiddleware({resources, tree: project}) {
return function versionInfo(req, res, next) {
resources.dependencies.byGlob("/resources/**/.library")
.then((resources) => {
resources.sort((a, b) => {
return a._project.metadata.name.localeCompare(b._project.metadata.name);
});
return createVersionInfoProcessor({
options: {
rootProjectName: project.metadata.name,
rootProjectVersion: project.version,
libraryInfos: resources.map((dotLibResource) => {
return {
name: dotLibResource._project.metadata.name,
version: dotLibResource._project.version
};
})
}
});
})
.then(([versionInfoResource]) => {
return versionInfoResource.getBuffer();
})
.then((versionInfoContent) => {
res.writeHead(200, {
"Content-Type": "application/json"
return async function versionInfo(req, res, next) {
try {
const dependencies = resources.dependencies;
const dotLibResources = await dependencies.byGlob("/resources/**/.library");

dotLibResources.sort((a, b) => {
return a._project.metadata.name.localeCompare(b._project.metadata.name);
});

const libraryInfosPromises = dotLibResources.map(async (dotLibResource) => {
const namespace = dotLibResource._project.metadata.namespace;
const manifestResources = await dependencies.byGlob(`/resources/${namespace}/**/${MANIFEST_JSON}`);
let libraryManifest = manifestResources.find((manifestResource) => {
return manifestResource.getPath() === `/resources/${namespace}/${MANIFEST_JSON}`;
});
res.end(versionInfoContent.toString());
})
.catch((err) => {
next(err);
const embeddedManifests =
manifestResources.filter((manifestResource) => manifestResource !== libraryManifest);
if (!libraryManifest) {
const extensions = "js,json,library,less,css,theming,theme,properties";
const libResources = await dependencies.byGlob(`/resources/${namespace}/**/*.{${extensions}}`);

libraryManifest = await createManifestProcessor({
libraryResource: dotLibResource,
namespace,
resources: libResources,
options: {
omitMinVersions: true
}
});
}
return {
libraryManifest,
embeddedManifests,
name: dotLibResource._project.metadata.name,
version: dotLibResource._project.version
};
});
const libraryInfos = await Promise.all(libraryInfosPromises);

const [versionInfoResource] = await createVersionInfoProcessor({
options: {
rootProjectName: project.metadata.name,
rootProjectVersion: project.version,
libraryInfos
}
});
const versionInfoContent = await versionInfoResource.getBuffer();

res.writeHead(200, {
"Content-Type": "application/json"
});
res.end(versionInfoContent.toString());
} catch (err) {
next(err);
}
};
}

Expand Down
21 changes: 21 additions & 0 deletions test/lib/server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,39 @@ test("Get sap-ui-version.json from versionInfo middleware (/resources/sap-ui-ver
"libraries": [
{
name: "library.a",
manifestHints: {
dependencies: {
libs: {
"library.d": {}
}
}
},
version: "1.0.0",
buildTimestamp,
scmRevision: ""
},
{
name: "library.b",
manifestHints: {
dependencies: {
libs: {
"library.d": {}
}
}
},
version: "1.0.0",
buildTimestamp,
scmRevision: ""
},
{
name: "library.c",
manifestHints: {
dependencies: {
libs: {
"library.d": {}
}
}
},
version: "1.0.0",
buildTimestamp,
scmRevision: ""
Expand Down
Loading