Fixed the version ordering for libs.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2019-11-22 14:01:40 +01:00
parent 6448b447b3
commit f359843635
4 changed files with 10 additions and 9 deletions

View File

@ -170,12 +170,6 @@ export interface BoardPackage extends ArduinoComponent {
id: string; id: string;
boards: Board[]; boards: Board[];
} }
export namespace BoardPackage {
/**
* Most recent version comes first, then the previous versions. (`1.8.1`, `1.6.3`, `1.6.2`, `1.6.1` and so on.)
*/
export const VERSION_COMPARATOR = (left: string, right: string) => naturalCompare(right, left);
}
export interface Board { export interface Board {
name: string name: string

View File

@ -1,3 +1,4 @@
const naturalCompare: (left: string, right: string) => number = require('string-natural-compare').caseInsensitive;
import { ArduinoComponent } from './arduino-component'; import { ArduinoComponent } from './arduino-component';
export interface Installable<T extends ArduinoComponent> { export interface Installable<T extends ArduinoComponent> {
@ -8,4 +9,10 @@ export interface Installable<T extends ArduinoComponent> {
} }
export namespace Installable { export namespace Installable {
export type Version = string; export type Version = string;
export namespace Version {
/**
* Most recent version comes first, then the previous versions. (`1.8.1`, `1.6.3`, `1.6.2`, `1.6.1` and so on.)
*/
export const COMPARATOR = (left: Version, right: Version) => naturalCompare(right, left);
}
} }

View File

@ -244,7 +244,7 @@ export class BoardsServiceImpl implements BoardsService {
const pkg = packages.get(id); const pkg = packages.get(id);
if (pkg) { if (pkg) {
pkg.availableVersions.push(platform.getLatest()); pkg.availableVersions.push(platform.getLatest());
pkg.availableVersions.sort(BoardPackage.VERSION_COMPARATOR); pkg.availableVersions.sort(Installable.Version.COMPARATOR);
} else { } else {
packages.set(id, toPackage(platform)); packages.set(id, toPackage(platform));
} }

View File

@ -47,7 +47,7 @@ export class LibraryServiceImpl implements LibraryService {
.slice(0, 50) .slice(0, 50)
.map(item => { .map(item => {
// TODO: This seems to contain only the latest item instead of all of the items. // TODO: This seems to contain only the latest item instead of all of the items.
const availableVersions = item.getReleasesMap().getEntryList().map(([key, _]) => key); const availableVersions = item.getReleasesMap().getEntryList().map(([key, _]) => key).sort(Installable.Version.COMPARATOR);
let installedVersion: string | undefined; let installedVersion: string | undefined;
const installed = installedLibsIdx.get(item.getName()); const installed = installedLibsIdx.get(item.getName());
if (installed) { if (installed) {