@@ -146,6 +146,7 @@ export class PlatformService implements IPlatformService {
146146 this . validatePlatform ( platform ) ;
147147
148148 platform = platform . toLowerCase ( ) ;
149+ this . ensurePlatformInstalled ( platform ) . wait ( ) ;
149150
150151 var platformData = this . $platformsData . getPlatformData ( platform ) ;
151152 let appDestinationDirectoryPath = path . join ( platformData . appDestinationDirectoryPath , constants . APP_FOLDER_NAME ) ;
@@ -233,21 +234,21 @@ export class PlatformService implements IPlatformService {
233234
234235 public updatePlatforms ( platforms : string [ ] ) : IFuture < void > {
235236 return ( ( ) => {
236- _ . each ( platforms , platform => {
237- var parts = platform . split ( "@" ) ;
238- platform = parts [ 0 ] . toLowerCase ( ) ;
239- var version = parts [ 1 ] ;
240-
241- this . validatePlatformInstalled ( platform ) ;
242- this . updatePlatform ( platform , version ) . wait ( ) ;
237+ _ . each ( platforms , platformParam => {
238+ let [ platform , version ] = platformParam . split ( "@" ) ;
239+ if ( this . isPlatformInstalled ( platform ) . wait ( ) ) {
240+ this . updatePlatform ( platform , version ) . wait ( ) ;
241+ } else {
242+ this . addPlatform ( platformParam ) . wait ( ) ;
243+ }
243244 } ) ;
244245 } ) . future < void > ( ) ( ) ;
245246 }
246247
247248 public deployOnDevice ( platform : string ) : IFuture < void > {
248249 return ( ( ) => {
249250 platform = platform . toLowerCase ( ) ;
250-
251+ this . ensurePlatformInstalled ( platform ) . wait ( ) ;
251252 var platformData = this . $platformsData . getPlatformData ( platform ) ;
252253
253254 var cachedDeviceOption = this . $options . forDevice ;
@@ -276,7 +277,7 @@ export class PlatformService implements IPlatformService {
276277
277278 public deployOnEmulator ( platform : string ) : IFuture < void > {
278279 return ( ( ) => {
279- this . validatePlatformInstalled ( platform ) ;
280+ this . ensurePlatformInstalled ( platform ) . wait ( ) ;
280281 platform = platform . toLowerCase ( ) ;
281282
282283 var platformData = this . $platformsData . getPlatformData ( platform ) ;
@@ -333,7 +334,15 @@ export class PlatformService implements IPlatformService {
333334 }
334335 } ) . future < void > ( ) ( ) ;
335336 }
336-
337+
338+ private ensurePlatformInstalled ( platform : string ) : IFuture < void > {
339+ return ( ( ) => {
340+ if ( ! this . isPlatformInstalled ( platform ) . wait ( ) ) {
341+ this . addPlatform ( platform ) . wait ( ) ;
342+ }
343+ } ) . future < void > ( ) ( ) ;
344+ }
345+
337346 private isPlatformInstalled ( platform : string ) : IFuture < boolean > {
338347 return this . $fs . exists ( path . join ( this . $projectData . platformsDir , platform . toLowerCase ( ) ) ) ;
339348 }
0 commit comments