#246 #247 include all installed versions of package in GuiPackage shape (#249)

* #246 #247 include all installed versions of package in GuiPackage.installed_versions

---------

Co-authored-by: neil <neil@neils-MacBook-Pro.local>
This commit is contained in:
Neil 2023-03-02 21:39:22 +08:00 committed by GitHub
parent beb882eef5
commit 076dd1d4eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 5 deletions

View file

@ -31,7 +31,6 @@ export async function getInstalledPackages() {
const pkgs = folders
.map((p: string) => p.split(".tea/")[1])
.filter((p: string) => !p.includes("tea.xyz"))
.map((p: string) => {
const path = p.trim().split("/");
const version = path.pop();

View file

@ -11,6 +11,7 @@
* - connect to a local platform api and returns a data
*/
import semverCompare from "semver/functions/compare";
import type { Package, Review, AirtablePost, Bottle } from "@tea/ui/types";
import type { GUIPackage, Course, Category, DeviceAuth, Session } from "./types";
@ -28,12 +29,17 @@ export async function getPackages(): Promise<GUIPackage[]> {
ipcRenderer.invoke("get-installed-packages") as { version: string; full_name: string }[]
]);
// sorts all packages from highest -> lowest
installedPackages.sort((a, b) => semverCompare(b.version, a.version));
return (packages || []).map((pkg) => {
const found = installedPackages.find((p) => p.full_name === pkg.full_name);
const installedVersions = installedPackages
.filter((p) => p.full_name === pkg.full_name)
.map((p) => p.version);
return {
...pkg,
state: found ? PackageStates.INSTALLED : PackageStates.AVAILABLE,
installed_version: found ? found.version : ""
state: installedVersions.length ? PackageStates.INSTALLED : PackageStates.AVAILABLE,
installed_versions: installedVersions
};
});
}

View file

@ -14,7 +14,7 @@ export enum PackageStates {
export type GUIPackage = Package & {
state: PackageStates;
installed_version?: string;
installed_versions?: string[];
synced?: boolean;
};