@@ -425,74 +425,72 @@ export class PlatformService implements IPlatformService {
425
425
426
426
this . ensurePackageIsCached ( platformData . frameworkPackageName , newVersion ) . wait ( ) ;
427
427
428
- if ( platformData . platformProjectService . canUpdatePlatform ( currentVersion , newVersion ) . wait ( ) ) {
429
-
428
+ let canUpdate = platformData . platformProjectService . canUpdatePlatform ( currentVersion , newVersion ) . wait ( ) ;
429
+ if ( canUpdate ) {
430
430
if ( ! semver . valid ( newVersion ) ) {
431
431
this . $errors . fail ( "The version %s is not valid. The version should consists from 3 parts separated by dot." , newVersion ) ;
432
432
}
433
433
434
434
if ( semver . gt ( currentVersion , newVersion ) ) { // Downgrade
435
- let isUpdateConfirmed = this . $prompter . confirm ( `You are going to downgrade to android runtime v.${ newVersion } . Are you sure?` , ( ) => false ) . wait ( ) ;
435
+ let isUpdateConfirmed = this . $prompter . confirm ( `You are going to downgrade to runtime v.${ newVersion } . Are you sure?` , ( ) => false ) . wait ( ) ;
436
436
if ( isUpdateConfirmed ) {
437
- this . updatePlatformCore ( platformData , currentVersion , newVersion ) . wait ( ) ;
437
+ this . updatePlatformCore ( platformData , currentVersion , newVersion , canUpdate ) . wait ( ) ;
438
438
}
439
439
} else if ( semver . eq ( currentVersion , newVersion ) ) {
440
440
this . $errors . fail ( "Current and new version are the same." ) ;
441
441
} else {
442
- this . updatePlatformCore ( platformData , currentVersion , newVersion ) . wait ( ) ;
442
+ this . updatePlatformCore ( platformData , currentVersion , newVersion , canUpdate ) . wait ( ) ;
443
443
}
444
444
} else {
445
- let isUpdateConfirmed = this . $prompter . confirm ( `We need to override xcodeproj file. The old one will be saved at ${ this . $options . profileDir } . Are you sure?` , ( ) => true ) . wait ( ) ;
446
- if ( isUpdateConfirmed ) {
447
- platformData . platformProjectService . updatePlatform ( currentVersion , newVersion ) . wait ( ) ;
448
- this . updatePlatformCore ( platformData , currentVersion , newVersion ) . wait ( ) ;
449
- }
445
+ this . updatePlatformCore ( platformData , currentVersion , newVersion , canUpdate ) . wait ( ) ;
450
446
}
451
447
452
448
} ) . future < void > ( ) ( ) ;
453
449
}
454
450
455
- private updatePlatformCore ( platformData : IPlatformData , currentVersion : string , newVersion : string ) : IFuture < void > {
451
+ private updatePlatformCore ( platformData : IPlatformData , currentVersion : string , newVersion : string , canUpdate : boolean ) : IFuture < void > {
456
452
return ( ( ) => {
457
- // Remove old framework files
458
- let oldFrameworkData = this . getFrameworkFiles ( platformData , currentVersion ) . wait ( ) ;
459
-
460
- _ . each ( oldFrameworkData . frameworkFiles , file => {
461
- let fileToDelete = path . join ( platformData . projectRoot , file ) ;
462
- this . $logger . trace ( "Deleting %s" , fileToDelete ) ;
463
- this . $fs . deleteFile ( fileToDelete ) . wait ( ) ;
464
- } ) ;
465
-
466
- _ . each ( oldFrameworkData . frameworkDirectories , dir => {
467
- let dirToDelete = path . join ( platformData . projectRoot , dir ) ;
468
- this . $logger . trace ( "Deleting %s" , dirToDelete ) ;
469
- this . $fs . deleteDirectory ( dirToDelete ) . wait ( ) ;
470
- } ) ;
453
+ let update = platformData . platformProjectService . updatePlatform ( currentVersion , newVersion , canUpdate ) . wait ( ) ;
454
+ if ( update ) {
455
+ // Remove old framework files
456
+ let oldFrameworkData = this . getFrameworkFiles ( platformData , currentVersion ) . wait ( ) ;
457
+
458
+ _ . each ( oldFrameworkData . frameworkFiles , file => {
459
+ let fileToDelete = path . join ( platformData . projectRoot , file ) ;
460
+ this . $logger . trace ( "Deleting %s" , fileToDelete ) ;
461
+ this . $fs . deleteFile ( fileToDelete ) . wait ( ) ;
462
+ } ) ;
471
463
472
- // Add new framework files
473
- let newFrameworkData = this . getFrameworkFiles ( platformData , newVersion ) . wait ( ) ;
474
- let cacheDirectoryPath = this . $npmInstallationManager . getCachedPackagePath ( platformData . frameworkPackageName , newVersion ) ;
464
+ _ . each ( oldFrameworkData . frameworkDirectories , dir => {
465
+ let dirToDelete = path . join ( platformData . projectRoot , dir ) ;
466
+ this . $logger . trace ( "Deleting %s" , dirToDelete ) ;
467
+ this . $fs . deleteDirectory ( dirToDelete ) . wait ( ) ;
468
+ } ) ;
475
469
476
- _ . each ( newFrameworkData . frameworkFiles , file => {
477
- let sourceFile = path . join ( cacheDirectoryPath , constants . PROJECT_FRAMEWORK_FOLDER_NAME , file ) ;
478
- let destinationFile = path . join ( platformData . projectRoot , file ) ;
479
- this . $logger . trace ( "Replacing %s with %s" , sourceFile , destinationFile ) ;
480
- shell . cp ( "-f" , sourceFile , destinationFile ) ;
481
- } ) ;
470
+ // Add new framework files
471
+ let newFrameworkData = this . getFrameworkFiles ( platformData , newVersion ) . wait ( ) ;
472
+ let cacheDirectoryPath = this . $npmInstallationManager . getCachedPackagePath ( platformData . frameworkPackageName , newVersion ) ;
482
473
483
- _ . each ( newFrameworkData . frameworkDirectories , dir => {
484
- let sourceDirectory = path . join ( cacheDirectoryPath , constants . PROJECT_FRAMEWORK_FOLDER_NAME , dir ) ;
485
- let destinationDirectory = path . join ( platformData . projectRoot , dir ) ;
486
- this . $logger . trace ( "Copying %s to %s" , sourceDirectory , destinationDirectory ) ;
487
- shell . cp ( "-fR " , path . join ( sourceDirectory , "*" ) , destinationDirectory ) ;
488
- } ) ;
474
+ _ . each ( newFrameworkData . frameworkFiles , file => {
475
+ let sourceFile = path . join ( cacheDirectoryPath , constants . PROJECT_FRAMEWORK_FOLDER_NAME , file ) ;
476
+ let destinationFile = path . join ( platformData . projectRoot , file ) ;
477
+ this . $logger . trace ( "Replacing %s with %s" , sourceFile , destinationFile ) ;
478
+ shell . cp ( "-f " , sourceFile , destinationFile ) ;
479
+ } ) ;
489
480
490
- // Update .tnsproject file
491
- this . $projectDataService . initialize ( this . $projectData . projectDir ) ;
492
- this . $projectDataService . setValue ( platformData . frameworkPackageName , { version : newVersion } ) . wait ( ) ;
481
+ _ . each ( newFrameworkData . frameworkDirectories , dir => {
482
+ let sourceDirectory = path . join ( cacheDirectoryPath , constants . PROJECT_FRAMEWORK_FOLDER_NAME , dir ) ;
483
+ let destinationDirectory = path . join ( platformData . projectRoot , dir ) ;
484
+ this . $logger . trace ( "Copying %s to %s" , sourceDirectory , destinationDirectory ) ;
485
+ shell . cp ( "-fR" , path . join ( sourceDirectory , "*" ) , destinationDirectory ) ;
486
+ } ) ;
493
487
494
- this . $logger . out ( "Successfully updated to version " , newVersion ) ;
488
+ // Update .tnsproject file
489
+ this . $projectDataService . initialize ( this . $projectData . projectDir ) ;
490
+ this . $projectDataService . setValue ( platformData . frameworkPackageName , { version : newVersion } ) . wait ( ) ;
495
491
492
+ this . $logger . out ( "Successfully updated to version " , newVersion ) ;
493
+ }
496
494
} ) . future < void > ( ) ( ) ;
497
495
}
498
496
0 commit comments