mirror of
https://github.com/ivabus/gui
synced 2025-04-23 14:07:14 +03:00
change init logic to not pull bottles (#337)
* change init logic to not pull bottles * prettier
This commit is contained in:
parent
718126cfc8
commit
aed776e79c
4 changed files with 14 additions and 60 deletions
|
@ -81,16 +81,15 @@ export async function getFeaturedPackages(): Promise<Package[]> {
|
|||
|
||||
export async function getPackageReviews(full_name: string): Promise<Review[]> {
|
||||
console.log(`getting reviews for ${full_name}`);
|
||||
const reviews: Review[] = await apiGet<Review[]>(
|
||||
`packages/${full_name.replaceAll("/", ":")}/reviews`
|
||||
);
|
||||
const reviews: Review[] =
|
||||
(await apiGet<Review[]>(`packages/${full_name.replaceAll("/", ":")}/reviews`)) ?? [];
|
||||
|
||||
return reviews;
|
||||
}
|
||||
|
||||
export async function installPackage(pkg: GUIPackage, version?: string) {
|
||||
try {
|
||||
const latestVersion = pkg?.available_versions?.length ? pkg.available_versions[0] : "";
|
||||
const latestVersion = pkg.version;
|
||||
const specificVersion = version || latestVersion;
|
||||
await installPackageCommand(pkg.full_name + (specificVersion ? `@${specificVersion}` : ""));
|
||||
} catch (error) {
|
||||
|
|
|
@ -2,16 +2,9 @@ import { writable } from "svelte/store";
|
|||
import type { GUIPackage, InstalledPackage } from "../types";
|
||||
import { PackageStates } from "../types";
|
||||
import Fuse from "fuse.js";
|
||||
import {
|
||||
getPackage,
|
||||
getDistPackages,
|
||||
getPackageBottles,
|
||||
openTerminal,
|
||||
getInstalledPackages
|
||||
} from "@native";
|
||||
import { getPackage, getDistPackages, openTerminal, getInstalledPackages } from "@native";
|
||||
|
||||
import { getReadme, getContributors, getRepoAsPackage } from "$libs/github";
|
||||
import semverCompare from "semver/functions/compare";
|
||||
import { notificationStore } from "../stores";
|
||||
import { NotificationType } from "@tea/ui/types";
|
||||
import type { Package } from "@tea/ui/types";
|
||||
|
@ -77,48 +70,11 @@ To read more about this package go to [${guiPkg.homepage}](${guiPkg.homepage}).
|
|||
updatePackage(guiPkg.full_name!, updatedPackage);
|
||||
};
|
||||
|
||||
const syncPackageBottlesAndState = async (pkgName: string): Promise<GUIPackage | void> => {
|
||||
const bottles = await getPackageBottles(pkgName);
|
||||
return new Promise((resolve) => {
|
||||
packages.update((pkgs) => {
|
||||
const i = pkgs.findIndex((pkg) => pkg.full_name === pkgName);
|
||||
if (i >= 0) {
|
||||
const pkg = pkgs[i];
|
||||
|
||||
const availableVersionsRaw = bottles
|
||||
.map(({ version }) => version)
|
||||
.sort((a, b) => semverCompare(b, a));
|
||||
|
||||
const availableVersions = new Set(availableVersionsRaw);
|
||||
|
||||
const installedVersions =
|
||||
pkg?.installed_versions?.sort((a, b) => semverCompare(b, a)) || [];
|
||||
|
||||
const it = availableVersions.values();
|
||||
const latestVersion = it.next().value;
|
||||
|
||||
pkgs[i] = {
|
||||
...pkg,
|
||||
available_versions: Array.from(availableVersions),
|
||||
state:
|
||||
latestVersion === installedVersions[0]
|
||||
? PackageStates.INSTALLED
|
||||
: PackageStates.NEEDS_UPDATE
|
||||
};
|
||||
|
||||
resolve(pkgs[i]);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
return pkgs;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const checkTeaCLIPackage = async (teaPkg: Package) => {
|
||||
const guiPkg = await syncPackageBottlesAndState(teaPkg.full_name);
|
||||
log.info("check Tea-CLI if state:", guiPkg?.state);
|
||||
if (guiPkg?.state === PackageStates.NEEDS_UPDATE && guiPkg?.installed_versions?.length) {
|
||||
const checkTeaCLIPackage = async (teaPkg: Package, installedPkg?: InstalledPackage) => {
|
||||
const isUpToDate = teaPkg.version === installedPkg?.installed_versions[0];
|
||||
log.info("check if Tea-CLI is up to date:", isUpToDate);
|
||||
//TODO: Is there where we handle the case of tea not being installed at all?
|
||||
if (!isUpToDate) {
|
||||
notificationStore.add({
|
||||
message: "install cli",
|
||||
i18n_key: "package.update-tea-cli",
|
||||
|
@ -153,7 +109,8 @@ To read more about this package go to [${guiPkg.homepage}](${guiPkg.homepage}).
|
|||
|
||||
log.info("sync test for tea-cli");
|
||||
const distTea = pkgs.find((p) => p.full_name === "tea.xyz");
|
||||
if (distTea) await checkTeaCLIPackage(distTea);
|
||||
const installedTeaVersions = installedPkgs.find((p) => p.full_name === "tea.xyz");
|
||||
if (distTea) await checkTeaCLIPackage(distTea, installedTeaVersions);
|
||||
|
||||
log.info("set NEEDS_UPDATE state to pkgs");
|
||||
let progressCount = 0;
|
||||
|
@ -166,10 +123,7 @@ To read more about this package go to [${guiPkg.homepage}](${guiPkg.homepage}).
|
|||
installed_versions: iPkg.installed_versions,
|
||||
state: isUpdated ? PackageStates.INSTALLED : PackageStates.NEEDS_UPDATE
|
||||
});
|
||||
log.info(`getting available bottles for ${pkg.full_name}`);
|
||||
await syncPackageBottlesAndState(iPkg.full_name);
|
||||
}
|
||||
log.info(`synced ${iPkg.full_name} ${progressCount}/${installedPkgs.length}`);
|
||||
syncProgress.set(+(progressCount / installedPkgs.length).toFixed(2));
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
|
@ -17,7 +17,6 @@ export type GUIPackage = Package & {
|
|||
state: PackageStates;
|
||||
installed_versions?: string[];
|
||||
synced?: boolean;
|
||||
available_versions?: string[];
|
||||
};
|
||||
|
||||
export type Course = {
|
||||
|
@ -65,4 +64,4 @@ export enum SideMenuOptions {
|
|||
made_by_tea = "made_by_tea"
|
||||
}
|
||||
|
||||
export type InstalledPackage = Require<Pick<GUIPackage, "full_name" | "installed_versions">>;
|
||||
export type InstalledPackage = Required<Pick<GUIPackage, "full_name" | "installed_versions">>;
|
||||
|
|
|
@ -7,12 +7,14 @@ export interface Review {
|
|||
}
|
||||
export interface Package {
|
||||
slug: string;
|
||||
// TODO: this field should be deprecated and instead be presented as a latest version PER architecture
|
||||
version: string;
|
||||
full_name: string;
|
||||
name: string;
|
||||
maintainer: string;
|
||||
homepage: string;
|
||||
last_modified: Date | string;
|
||||
created: Date | string;
|
||||
thumb_image_url: string;
|
||||
thumb_image_name: string;
|
||||
desc: string;
|
||||
|
|
Loading…
Reference in a new issue