@@ -310,7 +310,8 @@ export class PlatformService implements IPlatformService {
310310 this . $errors . fail ( "No platform specified." )
311311 }
312312
313- platform = platform . toLowerCase ( ) ;
313+ var parts = platform . split ( "@" ) ;
314+ platform = parts [ 0 ] . toLowerCase ( ) ;
314315
315316 if ( ! this . isValidPlatform ( platform ) ) {
316317 this . $errors . fail ( "Invalid platform %s. Valid platforms are %s." , platform , helpers . formatListOfNames ( this . $platformsData . platformsNames ) ) ;
@@ -442,19 +443,28 @@ export class PlatformService implements IPlatformService {
442443 var currentVersion = data && data . version ? data . version : "0.2.0" ;
443444 var newVersion = version || this . $npm . getLatestVersion ( platformData . frameworkPackageName ) . wait ( ) ;
444445
445- if ( ! semver . valid ( newVersion ) ) {
446- this . $errors . fail ( "The version %s is not valid. The version should consists from 3 parts seperated by dot." , newVersion ) ;
447- }
446+ if ( platformData . platformProjectService . canUpdatePlatform ( currentVersion , newVersion ) . wait ( ) ) {
448447
449- if ( semver . gt ( currentVersion , newVersion ) ) { // Downgrade
450- var isUpdateConfirmed = this . $prompter . confirm ( "You are going to update to lower version. Are you sure?" , ( ) => "n" ) . wait ( ) ;
451- 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 ( util . format ( "You are going to downgrade to android runtime v.%s. Are you sure?" , newVersion ) , ( ) => "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 {
452460 this . updatePlatformCore ( platformData , currentVersion , newVersion ) . wait ( ) ;
453461 }
454- } else if ( semver . eq ( currentVersion , newVersion ) ) {
455- this . $errors . fail ( "Current and new version are the same." ) ;
456462 } else {
457- 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+ }
458468 }
459469
460470 } ) . future < void > ( ) ( ) ;
@@ -463,16 +473,36 @@ export class PlatformService implements IPlatformService {
463473 private updatePlatformCore ( platformData : IPlatformData , currentVersion : string , newVersion : string ) : IFuture < void > {
464474 return ( ( ) => {
465475 // Remove old framework files
466- var oldFrameworkFiles = this . getFrameworkFiles ( platformData , currentVersion ) . wait ( ) ;
467- _ . each ( oldFrameworkFiles , file => {
468- this . $fs . deleteFile ( path . join ( platformData . projectRoot , file ) ) . wait ( ) ;
476+ var oldFrameworkData = this . getFrameworkFiles ( platformData , currentVersion ) . wait ( ) ;
477+
478+ _ . each ( oldFrameworkData . frameworkFiles , file => {
479+ var fileToDelete = path . join ( platformData . projectRoot , file ) ;
480+ this . $logger . trace ( "Deleting %s" , fileToDelete ) ;
481+ this . $fs . deleteFile ( fileToDelete ) . wait ( ) ;
482+ } ) ;
483+
484+ _ . each ( oldFrameworkData . frameworkDirectories , dir => {
485+ var dirToDelete = path . join ( platformData . projectRoot , dir ) ;
486+ this . $logger . trace ( "Deleting %s" , dirToDelete ) ;
487+ this . $fs . deleteDirectory ( dirToDelete ) . wait ( ) ;
469488 } ) ;
470489
471490 // Add new framework files
472- var newFrameworkFiles = this . getFrameworkFiles ( platformData , newVersion ) . wait ( ) ;
473- var cacheDirectoryPath = this . getNpmCacheDirectoryCore ( platformData . frameworkPackageName , newVersion ) ;
474- _ . each ( newFrameworkFiles , file => {
475- shell . cp ( "-f" , path . join ( cacheDirectoryPath , file ) , path . join ( platformData . projectRoot , file ) ) ;
491+ var newFrameworkData = this . getFrameworkFiles ( platformData , newVersion ) . wait ( ) ;
492+ var cacheDirectoryPath = this . $npm . getCachedPackagePath ( platformData . frameworkPackageName , newVersion ) ;
493+
494+ _ . each ( newFrameworkData . frameworkFiles , file => {
495+ var sourceFile = path . join ( cacheDirectoryPath , constants . PROJECT_FRAMEWORK_FOLDER_NAME , file ) ;
496+ var destinationFile = path . join ( platformData . projectRoot , file ) ;
497+ this . $logger . trace ( "Replacing %s with %s" , sourceFile , destinationFile ) ;
498+ shell . cp ( "-f" , sourceFile , destinationFile ) ;
499+ } ) ;
500+
501+ _ . each ( newFrameworkData . frameworkDirectories , dir => {
502+ var sourceDirectory = path . join ( cacheDirectoryPath , constants . PROJECT_FRAMEWORK_FOLDER_NAME , dir ) ;
503+ var destinationDirectory = path . join ( platformData . projectRoot , dir ) ;
504+ this . $logger . trace ( "Copying %s to %s" , sourceDirectory , destinationDirectory ) ;
505+ shell . cp ( "-fR" , path . join ( sourceDirectory , "*" ) , destinationDirectory ) ;
476506 } ) ;
477507
478508 // Update .tnsproject file
@@ -484,32 +514,35 @@ export class PlatformService implements IPlatformService {
484514 } ) . future < void > ( ) ( ) ;
485515 }
486516
487- private getFrameworkFiles ( platformData : IPlatformData , version : string ) : IFuture < string [ ] > {
517+ private getFrameworkFiles ( platformData : IPlatformData , version : string ) : IFuture < any > {
488518 return ( ( ) => {
489- var npmCacheDirectoryPath = this . getNpmCacheDirectory ( platformData . frameworkPackageName , version ) . wait ( ) ;
490- var allFiles = this . $fs . enumerateFilesInDirectorySync ( npmCacheDirectoryPath ) ;
519+ var cachedPackagePath = this . $npm . getCachedPackagePath ( platformData . frameworkPackageName , version ) ;
520+ this . ensurePackageIsCached ( cachedPackagePath , platformData . frameworkPackageName , version ) . wait ( ) ;
521+
522+ var allFiles = this . $fs . enumerateFilesInDirectorySync ( cachedPackagePath ) ;
491523 var filteredFiles = _ . filter ( allFiles , file => _ . contains ( platformData . frameworkFilesExtensions , path . extname ( file ) ) ) ;
492- var relativeToCacheFiles = _ . map ( filteredFiles , file => file . substr ( npmCacheDirectoryPath . length ) ) ;
493524
494- return relativeToCacheFiles ;
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 ) ) ;
526+ var filteredFrameworkDirectories = _ . filter ( allFrameworkDirectories , dir => this . $fs . getFsStats ( dir ) . wait ( ) . isDirectory ( ) && ( _ . contains ( platformData . frameworkFilesExtensions , path . extname ( dir ) ) || _ . contains ( platformData . frameworkDirectoriesNames , path . basename ( dir ) ) ) ) ;
495527
496- } ) . future < string [ ] > ( ) ( ) ;
528+ return {
529+ frameworkFiles : this . mapFrameworkFiles ( cachedPackagePath , filteredFiles ) ,
530+ frameworkDirectories : this . mapFrameworkFiles ( cachedPackagePath , filteredFrameworkDirectories )
531+ }
532+
533+ } ) . future < any > ( ) ( ) ;
497534 }
498535
499- private getNpmCacheDirectory ( packageName : string , version : string ) : IFuture < string > {
536+ private ensurePackageIsCached ( cachedPackagePath : string , packageName : string , version : string ) : IFuture < void > {
500537 return ( ( ) => {
501- var npmCacheDirectoryPath = this . getNpmCacheDirectoryCore ( packageName , version ) ;
502-
503- if ( ! this . $fs . exists ( npmCacheDirectoryPath ) . wait ( ) ) {
538+ if ( ! this . $fs . exists ( cachedPackagePath ) . wait ( ) ) {
504539 this . $npm . addToCache ( packageName , version ) . wait ( ) ;
505540 }
506-
507- return npmCacheDirectoryPath ;
508- } ) . future < string > ( ) ( ) ;
541+ } ) . future < void > ( ) ( ) ;
509542 }
510543
511- private getNpmCacheDirectoryCore ( packageName : string , version : string ) : string {
512- return path . join ( this . $npm . getCacheRootPath ( ) , packageName , version , "package" ) ;
544+ private mapFrameworkFiles ( npmCacheDirectoryPath : string , files : string [ ] ) : string [ ] {
545+ return _ . map ( files , file => file . substr ( npmCacheDirectoryPath . length + constants . PROJECT_FRAMEWORK_FOLDER_NAME . length + 1 ) )
513546 }
514547}
515548$injector . register ( "platformService" , PlatformService ) ;
0 commit comments