@@ -55,14 +55,14 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
55
55
private $localToDevicePathDataFactory : Mobile . ILocalToDevicePathDataFactory ,
56
56
protected $logger : ILogger ,
57
57
protected $options : ICommonOptions ,
58
- private $deviceAppDataFactory : Mobile . IDeviceAppDataFactory ,
58
+ protected $deviceAppDataFactory : Mobile . IDeviceAppDataFactory ,
59
59
private $fs : IFileSystem ,
60
- private $dispatcher : IFutureDispatcher ,
60
+ protected $dispatcher : IFutureDispatcher ,
61
61
protected $injector : IInjector ,
62
62
protected $childProcess : IChildProcess ,
63
63
protected $iOSEmulatorServices : Mobile . IiOSSimulatorService ,
64
64
protected $hooksService : IHooksService ,
65
- private $hostInfo : IHostInfo ) { }
65
+ protected $hostInfo : IHostInfo ) { }
66
66
67
67
public initialize ( platform : string ) : IFuture < string > {
68
68
return ( ( ) => {
@@ -78,72 +78,48 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
78
78
return this . _initialized ;
79
79
}
80
80
81
- public sync ( platform : string , appIdentifier : string , projectFilesPath : string , excludedProjectDirsAndFiles : string [ ] , watchGlob : any ,
82
- platformSpecificLiveSyncServices : IDictionary < any > ,
83
- notInstalledAppOnDeviceAction : ( _device1 : Mobile . IDevice ) => IFuture < boolean > ,
84
- notRunningiOSSimulatorAction : ( ) => IFuture < boolean > ,
85
- localProjectRootPath ?: string ,
86
- beforeLiveSyncAction ?: ( _device2 : Mobile . IDevice , _deviceAppData : Mobile . IDeviceAppData ) => IFuture < void > ,
87
- beforeBatchLiveSyncAction ?: ( _filePath : string ) => IFuture < string > ,
88
- iOSSimulatorRelativeToProjectBasePathAction ?: ( projectFile : string ) => string ,
89
- shouldRestartApplication ?: ( _localToDevicePaths : Mobile . ILocalToDevicePathData [ ] ) => IFuture < boolean > ) : IFuture < void > {
81
+ public sync ( data : ILiveSyncData ) : IFuture < void > {
90
82
return ( ( ) => {
91
- let platformLowerCase = platform . toLowerCase ( ) ;
92
- let synciOSSimulator = this . $hostInfo . isDarwin && platformLowerCase === "ios" && ( this . $options . emulator || this . $iOSEmulatorServices . isSimulatorRunning ( ) . wait ( ) ) ;
83
+ let synciOSSimulator = this . shouldSynciOSSimulator ( data . platform ) . wait ( ) ;
93
84
94
85
if ( synciOSSimulator ) {
95
- this . $iOSEmulatorServices . sync ( appIdentifier , projectFilesPath , notRunningiOSSimulatorAction ) . wait ( ) ;
86
+ this . $iOSEmulatorServices . sync ( data . appIdentifier , data . projectFilesPath , data . notRunningiOSSimulatorAction ) . wait ( ) ;
96
87
}
97
88
98
- if ( ! this . _initialized && ( ! this . $options . emulator || platform . toLowerCase ( ) === "android" ) ) {
99
- this . initialize ( platform ) . wait ( ) ;
89
+ if ( ! this . _initialized && ( ! this . $options . emulator || data . platform . toLowerCase ( ) === "android" ) ) {
90
+ this . initialize ( data . platform ) . wait ( ) ;
100
91
}
101
92
102
- if ( ! this . $options . emulator || platform . toLowerCase ( ) === "android" ) {
103
- let projectFiles = this . $fs . enumerateFilesInDirectorySync ( projectFilesPath ,
104
- ( filePath , stat ) => ! this . isFileExcluded ( path . relative ( projectFilesPath , filePath ) , excludedProjectDirsAndFiles , projectFilesPath ) ,
93
+ if ( ! this . $options . emulator || data . platform . toLowerCase ( ) === "android" ) {
94
+ let projectFiles = this . $fs . enumerateFilesInDirectorySync ( data . projectFilesPath ,
95
+ ( filePath , stat ) => ! this . isFileExcluded ( path . relative ( data . projectFilesPath , filePath ) , data . excludedProjectDirsAndFiles , data . projectFilesPath ) ,
105
96
{ enumerateDirectories : true }
106
97
) ;
107
98
108
- this . syncCore ( platform ,
109
- projectFiles ,
110
- appIdentifier ,
111
- localProjectRootPath || projectFilesPath ,
112
- platformSpecificLiveSyncServices ,
113
- notInstalledAppOnDeviceAction ,
114
- beforeLiveSyncAction ,
115
- shouldRestartApplication
116
- ) . wait ( ) ;
99
+ this . syncCore ( data , projectFiles ) . wait ( ) ;
117
100
}
118
101
119
102
if ( this . $options . watch ) {
103
+
120
104
let that = this ;
121
105
this . $hooksService . executeBeforeHooks ( 'watch' ) . wait ( ) ;
122
- gaze ( "**/*" , { cwd : watchGlob } , function ( err : any , watcher : any ) {
106
+
107
+ gaze ( "**/*" , { cwd : data . watchGlob } , function ( err : any , watcher : any ) {
123
108
this . on ( 'all' , ( event : string , filePath : string ) => {
124
109
if ( event === "added" || event === "changed" ) {
125
- if ( ! that . isFileExcluded ( filePath , excludedProjectDirsAndFiles , projectFilesPath ) ) {
110
+ if ( ! that . isFileExcluded ( filePath , data . excludedProjectDirsAndFiles , data . projectFilesPath ) ) {
111
+ let canExecuteFastLiveSync = data . canExecuteFastLiveSync && data . canExecuteFastLiveSync ( filePath ) ;
112
+
126
113
if ( synciOSSimulator ) {
127
- that . batchSimulatorLiveSync (
128
- appIdentifier ,
129
- projectFilesPath ,
130
- filePath ,
131
- notRunningiOSSimulatorAction ,
132
- iOSSimulatorRelativeToProjectBasePathAction
133
- ) ;
114
+ that . batchSimulatorLiveSync ( data , filePath ) ;
115
+ }
116
+
117
+ if ( ( ! that . $options . emulator || data . platform . toLowerCase ( ) === "android" ) && ! canExecuteFastLiveSync ) {
118
+ that . batchLiveSync ( data , filePath ) ;
134
119
}
135
120
136
- if ( ! that . $options . emulator || platform . toLowerCase ( ) === "android" ) {
137
- that . batchLiveSync (
138
- platform ,
139
- filePath ,
140
- appIdentifier ,
141
- localProjectRootPath || projectFilesPath ,
142
- platformSpecificLiveSyncServices ,
143
- notInstalledAppOnDeviceAction ,
144
- beforeLiveSyncAction ,
145
- beforeBatchLiveSyncAction
146
- ) ;
121
+ if ( canExecuteFastLiveSync ) {
122
+ data . fastLiveSync ( filePath ) ;
147
123
}
148
124
}
149
125
}
@@ -155,45 +131,61 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
155
131
} ) . future < void > ( ) ( ) ;
156
132
}
157
133
158
- private syncCore ( platform : string , projectFiles : string [ ] , appIdentifier : string , projectFilesPath : string ,
159
- platformSpecificLiveSyncServices : IDictionary < any > ,
160
- notInstalledAppOnDeviceAction : ( _device1 : Mobile . IDevice ) => IFuture < boolean > ,
161
- beforeLiveSyncAction ?: ( _device2 : Mobile . IDevice , _deviceAppData1 : Mobile . IDeviceAppData ) => IFuture < void > ,
162
- shouldRestartApplication ?: ( _localToDevicePaths : Mobile . ILocalToDevicePathData [ ] ) => IFuture < boolean > ) : IFuture < void > {
134
+ protected shouldSynciOSSimulator ( platform : string ) : IFuture < boolean > {
163
135
return ( ( ) => {
164
- platform = platform ? this . $mobileHelper . normalizePlatformName ( platform ) : this . $devicesService . platform ;
165
- let deviceAppData = this . $deviceAppDataFactory . create ( appIdentifier , platform ) ;
166
- let localToDevicePaths = _ ( projectFiles )
167
- . map ( projectFile => this . getProjectFileInfo ( projectFile ) )
168
- . filter ( projectFileInfo => projectFileInfo . shouldIncludeFile )
169
- . map ( projectFileInfo => this . $localToDevicePathDataFactory . create ( projectFileInfo . fileName , projectFilesPath , projectFileInfo . onDeviceName , deviceAppData . deviceProjectRootPath ) )
170
- . value ( ) ;
136
+ return this . $hostInfo . isDarwin && platform . toLowerCase ( ) === "ios" && ( this . $options . emulator || this . $iOSEmulatorServices . isSimulatorRunning ( ) . wait ( ) ) ;
137
+ } ) . future < boolean > ( ) ( ) ;
138
+ }
139
+
140
+ protected createLocalToDevicePaths ( platform : string , appIdentifier : string , projectFilesPath : string , projectFiles : string [ ] ) : Mobile . ILocalToDevicePathData [ ] {
141
+ let deviceAppData = this . $deviceAppDataFactory . create ( appIdentifier , this . $mobileHelper . normalizePlatformName ( platform ) ) ;
142
+ let localToDevicePaths = _ ( projectFiles )
143
+ . map ( projectFile => this . getProjectFileInfo ( projectFile ) )
144
+ . filter ( projectFileInfo => projectFileInfo . shouldIncludeFile )
145
+ . map ( projectFileInfo => this . $localToDevicePathDataFactory . create ( projectFileInfo . fileName , projectFilesPath , projectFileInfo . onDeviceName , deviceAppData . deviceProjectRootPath ) )
146
+ . value ( ) ;
147
+
148
+ return localToDevicePaths ;
149
+ }
150
+
151
+ protected transferFiles ( device : Mobile . IDevice , deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] ) : IFuture < void > {
152
+ return ( ( ) => {
153
+ this . $logger . info ( "Transferring project files..." ) ;
154
+ device . fileSystem . transferFiles ( deviceAppData . appIdentifier , localToDevicePaths ) . wait ( ) ;
155
+ this . $logger . info ( "Successfully transferred all project files." ) ;
156
+ } ) . future < void > ( ) ( ) ;
157
+ }
158
+
159
+ private syncCore ( data : ILiveSyncData , projectFiles : string [ ] ) : IFuture < void > {
160
+ return ( ( ) => {
161
+ let platform = data . platform ? this . $mobileHelper . normalizePlatformName ( data . platform ) : this . $devicesService . platform ;
162
+ let deviceAppData = this . $deviceAppDataFactory . create ( data . appIdentifier , this . $mobileHelper . normalizePlatformName ( data . platform ) ) ;
163
+ let localToDevicePaths = this . createLocalToDevicePaths ( data . platform , data . appIdentifier , data . localProjectRootPath || data . projectFilesPath , projectFiles ) ;
164
+
165
+ console . log ( localToDevicePaths [ 0 ] ) ;
171
166
172
167
let action = ( device : Mobile . IDevice ) => {
173
168
return ( ( ) => {
174
169
if ( deviceAppData . isLiveSyncSupported ( device ) . wait ( ) ) {
175
170
176
- if ( beforeLiveSyncAction ) {
177
- beforeLiveSyncAction ( device , deviceAppData ) . wait ( ) ;
171
+ if ( data . beforeLiveSyncAction ) {
172
+ data . beforeLiveSyncAction ( device , deviceAppData ) . wait ( ) ;
178
173
}
179
174
180
175
let applications = device . applicationManager . getInstalledApplications ( ) . wait ( ) ;
181
176
if ( ! _ . contains ( applications , deviceAppData . appIdentifier ) ) {
182
177
this . $logger . warn ( `The application with id "${ deviceAppData . appIdentifier } " is not installed on the device yet.` ) ;
183
- if ( ! notInstalledAppOnDeviceAction ( device ) . wait ( ) ) {
178
+ if ( ! data . notInstalledAppOnDeviceAction ( device ) . wait ( ) ) {
184
179
return ;
185
180
}
186
181
}
187
182
188
- this . $logger . info ( "Transferring project files..." ) ;
189
- device . fileSystem . transferFiles ( deviceAppData . appIdentifier , localToDevicePaths ) . wait ( ) ;
190
- this . $logger . info ( "Successfully transferred all project files." ) ;
183
+ this . transferFiles ( device , deviceAppData , localToDevicePaths ) . wait ( ) ;
184
+
185
+ this . $logger . info ( "Applying changes..." ) ;
186
+ let platformSpecificLiveSyncService = this . resolvePlatformSpecificLiveSyncService ( platform , device , data . platformSpecificLiveSyncServices ) ;
187
+ platformSpecificLiveSyncService . restartApplication ( deviceAppData , localToDevicePaths ) . wait ( ) ;
191
188
192
- if ( shouldRestartApplication && shouldRestartApplication ( localToDevicePaths ) . wait ( ) ) {
193
- this . $logger . info ( "Applying changes..." ) ;
194
- let platformSpecificLiveSyncService = this . resolvePlatformSpecificLiveSyncService ( platform , device , platformSpecificLiveSyncServices ) ;
195
- platformSpecificLiveSyncService . restartApplication ( deviceAppData , localToDevicePaths ) . wait ( ) ;
196
- }
197
189
this . $logger . info ( `Successfully synced application ${ deviceAppData . appIdentifier } .` ) ;
198
190
}
199
191
} ) . future < void > ( ) ( ) ;
@@ -205,46 +197,29 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
205
197
206
198
private batch : SyncBatch = null ;
207
199
208
- private batchLiveSync ( platform : string , filePath : string , appIdentifier : string , projectFilesPath : string ,
209
- platformSpecificLiveSyncServices : IDictionary < any > ,
210
- notInstalledAppOnDeviceAction : ( _device : Mobile . IDevice ) => IFuture < boolean > ,
211
- beforeLiveSyncAction ?: ( _device1 : Mobile . IDevice , _deviceAppData : Mobile . IDeviceAppData ) => IFuture < void > ,
212
- beforeBatchLiveSyncAction ?: ( _filePath : string ) => IFuture < string > ) : void {
200
+ private batchLiveSync ( data : ILiveSyncData , filePath : string ) : void {
213
201
if ( ! this . batch || ! this . batch . syncPending ) {
214
202
this . batch = new SyncBatch (
215
203
this . $logger , this . $dispatcher , ( filesToSync ) => {
216
- this . preparePlatformForSync ( platform ) ;
217
- this . syncCore (
218
- platform ,
219
- filesToSync ,
220
- appIdentifier ,
221
- projectFilesPath ,
222
- platformSpecificLiveSyncServices ,
223
- notInstalledAppOnDeviceAction ,
224
- beforeLiveSyncAction
225
- ) . wait ( ) ;
204
+ this . preparePlatformForSync ( data . platform ) ;
205
+ this . syncCore ( data , filesToSync ) . wait ( ) ;
226
206
}
227
207
) ;
228
208
}
229
209
230
210
this . $dispatcher . dispatch ( ( ) => ( ( ) => {
231
- let fileToSync = beforeBatchLiveSyncAction ? beforeBatchLiveSyncAction ( filePath ) . wait ( ) : filePath ;
211
+ let fileToSync = data . beforeBatchLiveSyncAction ? data . beforeBatchLiveSyncAction ( filePath ) . wait ( ) : filePath ;
232
212
if ( fileToSync ) {
233
213
this . batch . addFile ( fileToSync ) ;
234
214
}
235
215
} ) . future < void > ( ) ( ) ) ;
236
216
}
237
217
238
- private batchSimulatorLiveSync (
239
- appIdentifier : string ,
240
- projectFilesPath : string ,
241
- filePath : string ,
242
- notRunningiOSSimulatorAction : ( ) => IFuture < boolean > ,
243
- iOSSimulatorRelativeToProjectBasePathAction :( projectFile : string ) => string ) : void {
218
+ private batchSimulatorLiveSync ( data : ILiveSyncData , filePath : string ) : void {
244
219
if ( ! this . batch || ! this . batch . syncPending ) {
245
220
this . batch = new SyncBatch (
246
221
this . $logger , this . $dispatcher , ( filesToSync ) => {
247
- this . $iOSEmulatorServices . syncFiles ( appIdentifier , projectFilesPath , filesToSync , notRunningiOSSimulatorAction , iOSSimulatorRelativeToProjectBasePathAction ) ;
222
+ this . $iOSEmulatorServices . syncFiles ( data . appIdentifier , data . projectFilesPath , filesToSync , data . notRunningiOSSimulatorAction , data . iOSSimulatorRelativeToProjectBasePathAction ) ;
248
223
}
249
224
) ;
250
225
}
@@ -288,7 +263,7 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
288
263
return undefined ;
289
264
}
290
265
291
- private resolvePlatformSpecificLiveSyncService ( platform : string , device : Mobile . IDevice , platformSpecificLiveSyncServices : IDictionary < any > ) : IPlatformSpecificLiveSyncService {
266
+ protected resolvePlatformSpecificLiveSyncService ( platform : string , device : Mobile . IDevice , platformSpecificLiveSyncServices : IDictionary < any > ) : IPlatformSpecificUsbLiveSyncService {
292
267
return this . $injector . resolve ( platformSpecificLiveSyncServices [ platform . toLowerCase ( ) ] , { _device : device } ) ;
293
268
}
294
269
}
0 commit comments