@@ -443,19 +443,28 @@ export class PlatformService implements IPlatformService {
443443 var currentVersion = data && data . version ? data . version : "0.2.0" ;
444444 var newVersion = version || this . $npm . getLatestVersion ( platformData . frameworkPackageName ) . wait ( ) ;
445445
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 ( ) ) {
449447
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 {
453460 this . updatePlatformCore ( platformData , currentVersion , newVersion ) . wait ( ) ;
454461 }
455- } else if ( semver . eq ( currentVersion , newVersion ) ) {
456- this . $errors . fail ( "Current and new version are the same." ) ;
457462 } 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+ }
459468 }
460469
461470 } ) . future < void > ( ) ( ) ;
@@ -480,7 +489,7 @@ export class PlatformService implements IPlatformService {
480489
481490 // Add new framework files
482491 var newFrameworkData = this . getFrameworkFiles ( platformData , newVersion ) . wait ( ) ;
483- var cacheDirectoryPath = this . getNpmCacheDirectoryCore ( platformData . frameworkPackageName , newVersion ) ;
492+ var cacheDirectoryPath = this . $npm . getCachedPackagePath ( platformData . frameworkPackageName , newVersion ) ;
484493
485494 _ . each ( newFrameworkData . frameworkFiles , file => {
486495 var sourceFile = path . join ( cacheDirectoryPath , constants . PROJECT_FRAMEWORK_FOLDER_NAME , file ) ;
@@ -507,36 +516,29 @@ export class PlatformService implements IPlatformService {
507516
508517 private getFrameworkFiles ( platformData : IPlatformData , version : string ) : IFuture < any > {
509518 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 ( ) ;
511521
512- var allFiles = this . $fs . enumerateFilesInDirectorySync ( npmCacheDirectoryPath ) ;
522+ var allFiles = this . $fs . enumerateFilesInDirectorySync ( cachedPackagePath ) ;
513523 var filteredFiles = _ . filter ( allFiles , file => _ . contains ( platformData . frameworkFilesExtensions , path . extname ( file ) ) ) ;
514524
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 ) ) ;
516526 var filteredFrameworkDirectories = _ . filter ( allFrameworkDirectories , dir => this . $fs . getFsStats ( dir ) . wait ( ) . isDirectory ( ) && ( _ . contains ( platformData . frameworkFilesExtensions , path . extname ( dir ) ) || _ . contains ( platformData . frameworkDirectoriesNames , path . basename ( dir ) ) ) ) ;
517527
518528 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 )
521531 }
522532
523533 } ) . future < any > ( ) ( ) ;
524534 }
525535
526- private getNpmCacheDirectory ( packageName : string , version : string ) : IFuture < string > {
536+ private ensurePackageIsCached ( cachedPackagePath : string , packageName : string , version : string ) : IFuture < void > {
527537 return ( ( ) => {
528- var npmCacheDirectoryPath = this . getNpmCacheDirectoryCore ( packageName , version ) ;
529-
530- if ( ! this . $fs . exists ( npmCacheDirectoryPath ) . wait ( ) ) {
538+ if ( ! this . $fs . exists ( cachedPackagePath ) . wait ( ) ) {
531539 this . $npm . addToCache ( packageName , version ) . wait ( ) ;
532540 }
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 > ( ) ( ) ;
540542 }
541543
542544 private mapFrameworkFiles ( npmCacheDirectoryPath : string , files : string [ ] ) : string [ ] {
0 commit comments