Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / shared / lib / desktop / getLatestRelease.ts
blob1dac9fbac2d68e81c8b09fb87ac57e0884762a18
1 import { semver } from '@proton/pass/utils/string/semver';
2 import { RELEASE_CATEGORIES } from '@proton/shared/lib/constants';
3 import { type DesktopVersion } from '@proton/shared/lib/desktop/DesktopVersion';
5 export const getLatestRelease = (currentEnvironment: string | undefined, releaseList: DesktopVersion[]) => {
6     let latestRelease = undefined;
7     let latestReleaseSemver = 0;
9     for (const release of releaseList) {
10         const releaseSemver = semver(release.Version);
12         if (release.CategoryName === RELEASE_CATEGORIES.ALPHA && currentEnvironment !== 'alpha') {
13             continue;
14         }
16         if (
17             release.CategoryName === RELEASE_CATEGORIES.EARLY_ACCESS &&
18             currentEnvironment !== 'alpha' &&
19             currentEnvironment !== 'beta'
20         ) {
21             continue;
22         }
24         if (releaseSemver > latestReleaseSemver) {
25             latestRelease = release;
26             latestReleaseSemver = releaseSemver;
27         }
28     }
30     return latestRelease;