@@ -311,7 +311,8 @@ export class PlatformService implements IPlatformService {
311311 this . $errors . fail ( "No platform specified." )
312312 }
313313
314- platform = platform . toLowerCase ( ) ;
314+ var parts = platform . split ( "@" ) ;
315+ platform = parts [ 0 ] . toLowerCase ( ) ;
315316
316317 if ( ! this . isValidPlatform ( platform ) ) {
317318 this . $errors . fail ( "Invalid platform %s. Valid platforms are %s." , platform , helpers . formatListOfNames ( this . $platformsData . platformsNames ) ) ;
@@ -443,19 +444,28 @@ export class PlatformService implements IPlatformService {
443444 var currentVersion = data && data . version ? data . version : "0.2.0" ;
444445 var newVersion = version || this . $npm . getLatestVersion ( platformData . frameworkPackageName ) . wait ( ) ;
445446
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- }
447+ if ( platformData . platformProjectService . canUpdatePlatform ( currentVersion , newVersion ) . wait ( ) ) {
449448
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 ) {
449+ if ( ! semver . valid ( newVersion ) ) {
450+ this . $errors . fail ( "The version %s is not valid. The version should consists from 3 parts separated by dot." , newVersion ) ;
451+ }
452+
453+ if ( semver . gt ( currentVersion , newVersion ) ) { // Downgrade
454+ var isUpdateConfirmed = this . $prompter . confirm ( util . format ( "You are going to downgrade to android runtime v.%s. Are you sure?" , newVersion ) , ( ) => "n" ) . wait ( ) ;
455+ if ( isUpdateConfirmed ) {
456+ this . updatePlatformCore ( platformData , currentVersion , newVersion ) . wait ( ) ;
457+ }
458+ } else if ( semver . eq ( currentVersion , newVersion ) ) {
459+ this . $errors . fail ( "Current and new version are the same." ) ;
460+ } else {
453461 this . updatePlatformCore ( platformData , currentVersion , newVersion ) . wait ( ) ;
454462 }
455- } else if ( semver . eq ( currentVersion , newVersion ) ) {
456- this . $errors . fail ( "Current and new version are the same." ) ;
457463 } else {
458- this . updatePlatformCore ( platformData , currentVersion , newVersion ) . wait ( ) ;
464+ 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 ( ) ;
465+ if ( isUpdateConfirmed ) {
466+ platformData . platformProjectService . updatePlatform ( currentVersion , newVersion ) . wait ( ) ;
467+ this . updatePlatformCore ( platformData , currentVersion , newVersion ) . wait ( ) ;
468+ }
459469 }
460470
461471 } ) . future < void > ( ) ( ) ;
@@ -464,16 +474,36 @@ export class PlatformService implements IPlatformService {
464474 private updatePlatformCore ( platformData : IPlatformData , currentVersion : string , newVersion : string ) : IFuture < void > {
465475 return ( ( ) => {
466476 // Remove old framework files
467- var oldFrameworkFiles = this . getFrameworkFiles ( platformData , currentVersion ) . wait ( ) ;
468- _ . each ( oldFrameworkFiles , file => {
469- this . $fs . deleteFile ( path . join ( platformData . projectRoot , file ) ) . wait ( ) ;
477+ var oldFrameworkData = this . getFrameworkFiles ( platformData , currentVersion ) . wait ( ) ;
478+
479+ _ . each ( oldFrameworkData . frameworkFiles , file => {
480+ var fileToDelete = path . join ( platformData . projectRoot , file ) ;
481+ this . $logger . trace ( "Deleting %s" , fileToDelete ) ;
482+ this . $fs . deleteFile ( fileToDelete ) . wait ( ) ;
483+ } ) ;
484+
485+ _ . each ( oldFrameworkData . frameworkDirectories , dir => {
486+ var dirToDelete = path . join ( platformData . projectRoot , dir ) ;
487+ this . $logger . trace ( "Deleting %s" , dirToDelete ) ;
488+ this . $fs . deleteDirectory ( dirToDelete ) . wait ( ) ;
470489 } ) ;
471490
472491 // Add new framework files
473- var newFrameworkFiles = this . getFrameworkFiles ( platformData , newVersion ) . wait ( ) ;
474- var cacheDirectoryPath = this . getNpmCacheDirectoryCore ( platformData . frameworkPackageName , newVersion ) ;
475- _ . each ( newFrameworkFiles , file => {
476- shell . cp ( "-f" , path . join ( cacheDirectoryPath , file ) , path . join ( platformData . projectRoot , file ) ) ;
492+ var newFrameworkData = this . getFrameworkFiles ( platformData , newVersion ) . wait ( ) ;
493+ var cacheDirectoryPath = this . $npm . getCachedPackagePath ( platformData . frameworkPackageName , newVersion ) ;
494+
495+ _ . each ( newFrameworkData . frameworkFiles , file => {
496+ var sourceFile = path . join ( cacheDirectoryPath , constants . PROJECT_FRAMEWORK_FOLDER_NAME , file ) ;
497+ var destinationFile = path . join ( platformData . projectRoot , file ) ;
498+ this . $logger . trace ( "Replacing %s with %s" , sourceFile , destinationFile ) ;
499+ shell . cp ( "-f" , sourceFile , destinationFile ) ;
500+ } ) ;
501+
502+ _ . each ( newFrameworkData . frameworkDirectories , dir => {
503+ var sourceDirectory = path . join ( cacheDirectoryPath , constants . PROJECT_FRAMEWORK_FOLDER_NAME , dir ) ;
504+ var destinationDirectory = path . join ( platformData . projectRoot , dir ) ;
505+ this . $logger . trace ( "Copying %s to %s" , sourceDirectory , destinationDirectory ) ;
506+ shell . cp ( "-fR" , path . join ( sourceDirectory , "*" ) , destinationDirectory ) ;
477507 } ) ;
478508
479509 // Update .tnsproject file
@@ -485,32 +515,35 @@ export class PlatformService implements IPlatformService {
485515 } ) . future < void > ( ) ( ) ;
486516 }
487517
488- private getFrameworkFiles ( platformData : IPlatformData , version : string ) : IFuture < string [ ] > {
518+ private getFrameworkFiles ( platformData : IPlatformData , version : string ) : IFuture < any > {
489519 return ( ( ) => {
490- var npmCacheDirectoryPath = this . getNpmCacheDirectory ( platformData . frameworkPackageName , version ) . wait ( ) ;
491- var allFiles = this . $fs . enumerateFilesInDirectorySync ( npmCacheDirectoryPath ) ;
520+ var cachedPackagePath = this . $npm . getCachedPackagePath ( platformData . frameworkPackageName , version ) ;
521+ this . ensurePackageIsCached ( cachedPackagePath , platformData . frameworkPackageName , version ) . wait ( ) ;
522+
523+ var allFiles = this . $fs . enumerateFilesInDirectorySync ( cachedPackagePath ) ;
492524 var filteredFiles = _ . filter ( allFiles , file => _ . contains ( platformData . frameworkFilesExtensions , path . extname ( file ) ) ) ;
493- var relativeToCacheFiles = _ . map ( filteredFiles , file => file . substr ( npmCacheDirectoryPath . length ) ) ;
494525
495- return relativeToCacheFiles ;
526+ 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 ) ) ;
527+ var filteredFrameworkDirectories = _ . filter ( allFrameworkDirectories , dir => this . $fs . getFsStats ( dir ) . wait ( ) . isDirectory ( ) && ( _ . contains ( platformData . frameworkFilesExtensions , path . extname ( dir ) ) || _ . contains ( platformData . frameworkDirectoriesNames , path . basename ( dir ) ) ) ) ;
496528
497- } ) . future < string [ ] > ( ) ( ) ;
529+ return {
530+ frameworkFiles : this . mapFrameworkFiles ( cachedPackagePath , filteredFiles ) ,
531+ frameworkDirectories : this . mapFrameworkFiles ( cachedPackagePath , filteredFrameworkDirectories )
532+ }
533+
534+ } ) . future < any > ( ) ( ) ;
498535 }
499536
500- private getNpmCacheDirectory ( packageName : string , version : string ) : IFuture < string > {
537+ private ensurePackageIsCached ( cachedPackagePath : string , packageName : string , version : string ) : IFuture < void > {
501538 return ( ( ) => {
502- var npmCacheDirectoryPath = this . getNpmCacheDirectoryCore ( packageName , version ) ;
503-
504- if ( ! this . $fs . exists ( npmCacheDirectoryPath ) . wait ( ) ) {
539+ if ( ! this . $fs . exists ( cachedPackagePath ) . wait ( ) ) {
505540 this . $npm . addToCache ( packageName , version ) . wait ( ) ;
506541 }
507-
508- return npmCacheDirectoryPath ;
509- } ) . future < string > ( ) ( ) ;
542+ } ) . future < void > ( ) ( ) ;
510543 }
511544
512- private getNpmCacheDirectoryCore ( packageName : string , version : string ) : string {
513- return path . join ( this . $npm . getCacheRootPath ( ) , packageName , version , "package" ) ;
545+ private mapFrameworkFiles ( npmCacheDirectoryPath : string , files : string [ ] ) : string [ ] {
546+ return _ . map ( files , file => file . substr ( npmCacheDirectoryPath . length + constants . PROJECT_FRAMEWORK_FOLDER_NAME . length + 1 ) )
514547 }
515548}
516549$injector . register ( "platformService" , PlatformService ) ;
0 commit comments