@@ -16,6 +16,8 @@ class LiveSyncService implements ILiveSyncService {
1616 private $projectDataService : IProjectDataService ,
1717 private $prompter : IPrompter ,
1818 private $injector : IInjector ,
19+ private $mobileHelper : Mobile . IMobileHelper ,
20+ private $devicesService : Mobile . IDevicesService ,
1921 private $options : IOptions ) { }
2022
2123 private ensureAndroidFrameworkVersion ( platformData : IPlatformData ) : IFuture < void > { // TODO: this can be moved inside command or canExecute function
@@ -42,32 +44,50 @@ class LiveSyncService implements ILiveSyncService {
4244
4345 public liveSync ( platform : string ) : IFuture < void > {
4446 return ( ( ) => {
45- platform = this . $liveSyncServiceBase . getPlatform ( platform ) . wait ( ) ;
46- let platformLowerCase = platform . toLowerCase ( ) ;
47-
48- if ( ! this . $platformService . preparePlatform ( platformLowerCase ) . wait ( ) ) {
49- this . $errors . failWithoutHelp ( "Verify that listed files are well-formed and try again the operation." ) ;
47+ let liveSyncData : ILiveSyncData [ ] = [ ] ;
48+ this . $devicesService . initialize ( { skipInferPlatform : true } ) . wait ( ) ;
49+ if ( platform ) {
50+ liveSyncData . push ( this . prepareLiveSyncData ( platform ) ) ;
51+ } else if ( this . $options . device ) {
52+ platform = this . $devicesService . getDeviceByIdentifier ( this . $options . device ) . deviceInfo . platform ;
53+ liveSyncData . push ( this . prepareLiveSyncData ( platform ) ) ;
54+ } else {
55+ for ( let installedPlatform of this . $platformService . getInstalledPlatforms ( ) . wait ( ) ) {
56+ liveSyncData . push ( this . prepareLiveSyncData ( installedPlatform ) ) ;
57+ }
5058 }
5159
5260 this . _isInitialized = true ; // If we want before-prepare hooks to work properly, this should be set after preparePlatform function
5361
54- this . liveSyncCore ( platform ) . wait ( ) ;
62+ this . liveSyncCore ( liveSyncData ) . wait ( ) ;
5563 } ) . future < void > ( ) ( ) ;
5664 }
5765
66+ private prepareLiveSyncData ( platform : string ) : ILiveSyncData {
67+ platform = this . $liveSyncServiceBase . getPlatform ( platform ) . wait ( ) ;
68+ if ( ! this . $platformService . preparePlatform ( platform . toLowerCase ( ) ) . wait ( ) ) {
69+ this . $errors . failWithoutHelp ( "Verify that listed files are well-formed and try again the operation." ) ;
70+ }
71+
72+ let platformData = this . $platformsData . getPlatformData ( platform . toLowerCase ( ) ) ;
73+ if ( this . $mobileHelper . isAndroidPlatform ( platform ) ) {
74+ this . ensureAndroidFrameworkVersion ( platformData ) . wait ( ) ;
75+ }
76+ let liveSyncData : ILiveSyncData = {
77+ platform : platform ,
78+ appIdentifier : this . $projectData . projectId ,
79+ projectFilesPath : path . join ( platformData . appDestinationDirectoryPath , constants . APP_FOLDER_NAME ) ,
80+ syncWorkingDirectory : path . join ( this . $projectData . projectDir , constants . APP_FOLDER_NAME ) ,
81+ excludedProjectDirsAndFiles : this . $options . release ? constants . LIVESYNC_EXCLUDED_FILE_PATTERNS : [ ] ,
82+ forceExecuteFullSync : this . forceExecuteFullSync
83+ } ;
84+
85+ return liveSyncData ;
86+ }
87+
5888 @helpers . hook ( 'livesync' )
59- private liveSyncCore ( platform : string ) : IFuture < void > {
89+ private liveSyncCore ( liveSyncData : ILiveSyncData [ ] ) : IFuture < void > {
6090 return ( ( ) => {
61- let platformData = this . $platformsData . getPlatformData ( platform . toLowerCase ( ) ) ;
62- this . ensureAndroidFrameworkVersion ( platformData ) . wait ( ) ;
63- let liveSyncData : ILiveSyncData = {
64- platform : platform ,
65- appIdentifier : this . $projectData . projectId ,
66- projectFilesPath : path . join ( platformData . appDestinationDirectoryPath , constants . APP_FOLDER_NAME ) ,
67- syncWorkingDirectory : path . join ( this . $projectData . projectDir , constants . APP_FOLDER_NAME ) ,
68- excludedProjectDirsAndFiles : this . $options . release ? constants . LIVESYNC_EXCLUDED_FILE_PATTERNS : [ ] ,
69- forceExecuteFullSync : this . forceExecuteFullSync
70- } ;
7191 this . $liveSyncServiceBase . sync ( liveSyncData ) . wait ( ) ;
7292 } ) . future < void > ( ) ( ) ;
7393 }
0 commit comments