@@ -443,19 +443,28 @@ export class PlatformService implements IPlatformService {
443
443
var currentVersion = data && data . version ? data . version : "0.2.0" ;
444
444
var newVersion = version || this . $npm . getLatestVersion ( platformData . frameworkPackageName ) . wait ( ) ;
445
445
446
- if ( ! semver . valid ( newVersion ) ) {
447
- this . $errors . fail ( "The version %s is not valid. The version should consists from 3 parts seperated by dot." , newVersion ) ;
448
- }
446
+ if ( platformData . platformProjectService . canUpdatePlatform ( currentVersion , newVersion ) . wait ( ) ) {
449
447
450
- if ( semver . gt ( currentVersion , newVersion ) ) { // Downgrade
451
- var isUpdateConfirmed = this . $prompter . confirm ( "You are going to update to lower version. Are you sure?" , ( ) => "n" ) . wait ( ) ;
452
- if ( isUpdateConfirmed ) {
448
+ if ( ! semver . valid ( newVersion ) ) {
449
+ this . $errors . fail ( "The version %s is not valid. The version should consists from 3 parts separated by dot." , newVersion ) ;
450
+ }
451
+
452
+ if ( semver . gt ( currentVersion , newVersion ) ) { // Downgrade
453
+ var isUpdateConfirmed = this . $prompter . confirm ( "You are going to update to lower version. Are you sure?" , ( ) => "n" ) . wait ( ) ;
454
+ if ( isUpdateConfirmed ) {
455
+ this . updatePlatformCore ( platformData , currentVersion , newVersion ) . wait ( ) ;
456
+ }
457
+ } else if ( semver . eq ( currentVersion , newVersion ) ) {
458
+ this . $errors . fail ( "Current and new version are the same." ) ;
459
+ } else {
453
460
this . updatePlatformCore ( platformData , currentVersion , newVersion ) . wait ( ) ;
454
461
}
455
- } else if ( semver . eq ( currentVersion , newVersion ) ) {
456
- this . $errors . fail ( "Current and new version are the same." ) ;
457
462
} else {
458
- this . updatePlatformCore ( platformData , currentVersion , newVersion ) . wait ( ) ;
463
+ var isUpdateConfirmed = this . $prompter . confirm ( util . format ( "We need to override xcodeproj file. The old one will be saved at %s Are you sure?" , options . profileDir ) , ( ) => "y" ) . wait ( ) ;
464
+ if ( isUpdateConfirmed ) {
465
+ platformData . platformProjectService . updatePlatform ( currentVersion , newVersion ) . wait ( ) ;
466
+ this . updatePlatformCore ( platformData , currentVersion , newVersion ) . wait ( ) ;
467
+ }
459
468
}
460
469
461
470
} ) . future < void > ( ) ( ) ;
@@ -480,7 +489,7 @@ export class PlatformService implements IPlatformService {
480
489
481
490
// Add new framework files
482
491
var newFrameworkData = this . getFrameworkFiles ( platformData , newVersion ) . wait ( ) ;
483
- var cacheDirectoryPath = this . getNpmCacheDirectoryCore ( platformData . frameworkPackageName , newVersion ) ;
492
+ var cacheDirectoryPath = this . $npm . getCachedPackagePath ( platformData . frameworkPackageName , newVersion ) ;
484
493
485
494
_ . each ( newFrameworkData . frameworkFiles , file => {
486
495
var sourceFile = path . join ( cacheDirectoryPath , constants . PROJECT_FRAMEWORK_FOLDER_NAME , file ) ;
@@ -507,36 +516,29 @@ export class PlatformService implements IPlatformService {
507
516
508
517
private getFrameworkFiles ( platformData : IPlatformData , version : string ) : IFuture < any > {
509
518
return ( ( ) => {
510
- var npmCacheDirectoryPath = this . getNpmCacheDirectory ( platformData . frameworkPackageName , version ) . wait ( ) ;
519
+ var cachedPackagePath = this . $npm . getCachedPackagePath ( platformData . frameworkPackageName , version ) ;
520
+ this . ensurePackageIsCached ( cachedPackagePath , platformData . frameworkPackageName , version ) . wait ( ) ;
511
521
512
- var allFiles = this . $fs . enumerateFilesInDirectorySync ( npmCacheDirectoryPath ) ;
522
+ var allFiles = this . $fs . enumerateFilesInDirectorySync ( cachedPackagePath ) ;
513
523
var filteredFiles = _ . filter ( allFiles , file => _ . contains ( platformData . frameworkFilesExtensions , path . extname ( file ) ) ) ;
514
524
515
- var allFrameworkDirectories = _ . map ( this . $fs . readDirectory ( path . join ( npmCacheDirectoryPath , constants . PROJECT_FRAMEWORK_FOLDER_NAME ) ) . wait ( ) , dir => path . join ( npmCacheDirectoryPath , constants . PROJECT_FRAMEWORK_FOLDER_NAME , dir ) ) ;
525
+ var allFrameworkDirectories = _ . map ( this . $fs . readDirectory ( path . join ( cachedPackagePath , constants . PROJECT_FRAMEWORK_FOLDER_NAME ) ) . wait ( ) , dir => path . join ( cachedPackagePath , constants . PROJECT_FRAMEWORK_FOLDER_NAME , dir ) ) ;
516
526
var filteredFrameworkDirectories = _ . filter ( allFrameworkDirectories , dir => this . $fs . getFsStats ( dir ) . wait ( ) . isDirectory ( ) && ( _ . contains ( platformData . frameworkFilesExtensions , path . extname ( dir ) ) || _ . contains ( platformData . frameworkDirectoriesNames , path . basename ( dir ) ) ) ) ;
517
527
518
528
return {
519
- frameworkFiles : this . mapFrameworkFiles ( npmCacheDirectoryPath , filteredFiles ) ,
520
- frameworkDirectories : this . mapFrameworkFiles ( npmCacheDirectoryPath , filteredFrameworkDirectories )
529
+ frameworkFiles : this . mapFrameworkFiles ( cachedPackagePath , filteredFiles ) ,
530
+ frameworkDirectories : this . mapFrameworkFiles ( cachedPackagePath , filteredFrameworkDirectories )
521
531
}
522
532
523
533
} ) . future < any > ( ) ( ) ;
524
534
}
525
535
526
- private getNpmCacheDirectory ( packageName : string , version : string ) : IFuture < string > {
536
+ private ensurePackageIsCached ( cachedPackagePath : string , packageName : string , version : string ) : IFuture < void > {
527
537
return ( ( ) => {
528
- var npmCacheDirectoryPath = this . getNpmCacheDirectoryCore ( packageName , version ) ;
529
-
530
- if ( ! this . $fs . exists ( npmCacheDirectoryPath ) . wait ( ) ) {
538
+ if ( ! this . $fs . exists ( cachedPackagePath ) . wait ( ) ) {
531
539
this . $npm . addToCache ( packageName , version ) . wait ( ) ;
532
540
}
533
-
534
- return npmCacheDirectoryPath ;
535
- } ) . future < string > ( ) ( ) ;
536
- }
537
-
538
- private getNpmCacheDirectoryCore ( packageName : string , version : string ) : string {
539
- return path . join ( this . $npm . getCacheRootPath ( ) , packageName , version , "package" ) ;
541
+ } ) . future < void > ( ) ( ) ;
540
542
}
541
543
542
544
private mapFrameworkFiles ( npmCacheDirectoryPath : string , files : string [ ] ) : string [ ] {
0 commit comments