import { field_cmp } from "@cocalc/util/misc";
import {
ComputeComponents,
ComputeInventory,
Item,
LanguageName,
SoftwareSpec,
} from "./types";
export function getLibaries(
spec: SoftwareSpec[LanguageName],
inventory: ComputeInventory[LanguageName],
components: ComputeComponents[LanguageName]
): Item[] {
const libs: Item[] = [];
for (const name in components) {
const { url, summary } = components[name] ?? {};
const item: Item = {
index: libs.length,
name,
key: name.toLowerCase(),
summary: summary ?? "",
url: url?.split(",")[0],
search: (name + (summary ?? "")).toLowerCase(),
};
for (const env in spec) {
const envInfo = inventory[spec[env].cmd]?.[name];
if (envInfo != null) item[env] = envInfo;
}
libs.push(item);
}
libs.sort(field_cmp("key"));
return libs;
}