@@ -6,7 +6,7 @@ import { IDependency, IStarters } from ".";
66import { IHandlerItem } from "../handler/HandlerInterfaces" ;
77import { downloadFile } from "../Utils" ;
88import { matchRange } from "../Utils/VersionHelper" ;
9- import { DependencyGroup , Identifiable , MatadataType , Metadata } from "./Metadata" ;
9+ import { DependencyGroup , Identifiable , MetadataType , Metadata } from "./Metadata" ;
1010
1111/**
1212 * Prefer v2.2 and fallback to v2.1
@@ -17,44 +17,57 @@ const METADATA_HEADERS = { Accept: "application/vnd.initializr.v2.2+json,applica
1717class ServiceManager {
1818 private metadataMap : Map < string , Metadata > = new Map ( ) ;
1919
20- public async getItems < T extends Identifiable > ( serviceUrl : string , type : MatadataType ) : Promise < Array < IHandlerItem < T > > > {
20+ public async getItems < T extends Identifiable > ( serviceUrl : string , type : MetadataType ) : Promise < Array < IHandlerItem < T > > > {
2121 const metadata = await this . ensureMetadata ( serviceUrl ) ;
2222 if ( ! metadata ) {
2323 throw new Error ( "Failed to fetch metadata." ) ;
2424 }
2525 let defaultLabel : string ;
2626 let values : any [ ] ;
2727 switch ( type ) {
28- case MatadataType . BOOTVERSION :
28+ case MetadataType . BOOTVERSION :
2929 defaultLabel = metadata . bootVersion . default ;
3030 values = metadata . bootVersion . values ;
3131 break ;
32- case MatadataType . JAVAVERSION :
32+ case MetadataType . JAVAVERSION :
3333 defaultLabel = metadata . javaVersion . default ;
3434 values = metadata . javaVersion . values ;
3535 break ;
36- case MatadataType . LANGUAGE :
36+ case MetadataType . LANGUAGE :
3737 defaultLabel = metadata . language . default ;
3838 values = metadata . language . values ;
3939 break ;
40- case MatadataType . PACKAGING :
40+ case MetadataType . PACKAGING :
4141 defaultLabel = metadata . packaging . default ;
4242 values = metadata . packaging . values ;
4343 break ;
4444 default :
4545 throw new Error ( "Invalid metadata type." ) ;
4646 }
4747
48- const sortedValues = values . filter ( x => x . id === defaultLabel ) . concat ( values . filter ( x => x . id !== defaultLabel ) ) ;
48+ const defaultValues = values . filter ( x => x . id === defaultLabel ) ;
49+ const nonDefaultValues = values . filter ( x => x . id !== defaultLabel ) ;
50+
51+ let mappedDefault : Array < IHandlerItem < T > > = this . mapValues ( defaultValues , type , true ) ;
52+ let mappedNonDefault : Array < IHandlerItem < T > > = this . mapValues ( nonDefaultValues , type , false ) ;
53+
54+ return mappedDefault . concat ( mappedNonDefault ) ;
55+ }
56+
57+ private mapValues < T extends Identifiable > (
58+ items : any [ ] ,
59+ type : MetadataType ,
60+ isDefault : boolean
61+ ) : Array < IHandlerItem < T > > {
4962 switch ( type ) {
50- case MatadataType . BOOTVERSION :
51- return sortedValues . map ( v => ( { value : v , label : v . name } ) ) ;
52- case MatadataType . JAVAVERSION :
53- return sortedValues . map ( v => ( { value : v , label : v . name } ) ) ;
63+ case MetadataType . BOOTVERSION :
64+ return items . map ( v => ( { value : v , label : v . name , default : isDefault } ) )
65+ case MetadataType . JAVAVERSION :
66+ return items . map ( v => ( { value : v , label : v . name , default : isDefault } ) ) ;
5467 default :
55- return sortedValues . map ( v => ( { label : v . name } ) ) ;
68+ return items . map ( v => ( { label : v . name , default : isDefault } ) ) ;
5669 }
57- }
70+ }
5871
5972 public async getAvailableDependencies ( serviceUrl : string , bootVersion : string ) : Promise < IDependency [ ] > {
6073 const metadata = await this . ensureMetadata ( serviceUrl ) ;
0 commit comments