1
1
import * as path from "path" ;
2
2
import * as choki from "chokidar" ;
3
3
import { EventEmitter } from "events" ;
4
- import { exported } from "../../common/decorators" ;
5
4
import { hook } from "../../common/helpers" ;
5
+ import { FileExtensions } from "../../common/constants" ;
6
6
7
7
const LiveSyncEvents = {
8
8
liveSyncStopped : "liveSyncStopped" ,
@@ -30,8 +30,6 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
30
30
super ( ) ;
31
31
}
32
32
33
- // TODO: Add finishLivesync method in the platform specific services
34
- @exported ( "liveSyncService" )
35
33
@hook ( "liveSync" )
36
34
public async liveSync ( deviceDescriptors : ILiveSyncDeviceInfo [ ] ,
37
35
liveSyncData : ILiveSyncInfo ) : Promise < void > {
@@ -54,7 +52,6 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
54
52
}
55
53
}
56
54
57
- @exported ( "liveSyncService" )
58
55
public async stopLiveSync ( projectDir : string , deviceIdentifiers ?: string [ ] , ) : Promise < void > {
59
56
const liveSyncProcessInfo = this . liveSyncProcessesInfo [ projectDir ] ;
60
57
@@ -91,7 +88,12 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
91
88
92
89
// Kill typescript watcher
93
90
// TODO: Pass the projectDir in hooks args.
94
- await this . $hooksService . executeAfterHooks ( 'watch' ) ;
91
+ const projectData = this . $projectDataService . getProjectData ( projectDir ) ;
92
+ await this . $hooksService . executeAfterHooks ( 'watch' , {
93
+ hookArgs : {
94
+ projectData
95
+ }
96
+ } ) ;
95
97
96
98
this . emit ( LiveSyncEvents . liveSyncStopped , { projectDir } ) ;
97
99
}
@@ -155,7 +157,10 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
155
157
if ( preparedPlatforms . indexOf ( platform ) === - 1 ) {
156
158
preparedPlatforms . push ( platform ) ;
157
159
// TODO: fix args cast to any
158
- await this . $platformService . preparePlatform ( platform , < any > { } , null , projectData , < any > { } , modifiedFiles ) ;
160
+ await this . $platformService . preparePlatform ( platform , {
161
+ bundle : false ,
162
+ release : false ,
163
+ } , null , projectData , < any > { } , modifiedFiles ) ;
159
164
}
160
165
161
166
const rebuildInfo = _ . find ( rebuiltInformation , info => info . isEmulator === device . isEmulator && info . platform === platform ) ;
@@ -169,18 +174,16 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
169
174
170
175
// TODO: fix args cast to any
171
176
const shouldBuild = await this . $platformService . shouldBuild ( platform , projectData , < any > { buildForDevice : ! device . isEmulator } , deviceBuildInfoDescriptor . outputPath ) ;
177
+ let pathToBuildItem = null ;
172
178
if ( shouldBuild ) {
173
- const pathToBuildItem = await deviceBuildInfoDescriptor . buildAction ( ) ;
179
+ pathToBuildItem = await deviceBuildInfoDescriptor . buildAction ( ) ;
174
180
// Is it possible to return shouldBuild for two devices? What about android device and android emulator?
175
181
rebuiltInformation . push ( { isEmulator : device . isEmulator , platform, pathToBuildItem } ) ;
176
- await this . $platformService . installApplication ( device , { release : false } , projectData , pathToBuildItem , deviceBuildInfoDescriptor . outputPath ) ;
177
-
178
182
}
179
183
180
184
const shouldInstall = await this . $platformService . shouldInstall ( device , projectData , deviceBuildInfoDescriptor . outputPath ) ;
181
185
if ( shouldInstall ) {
182
-
183
- await this . $platformService . installApplication ( device , { release : false } , projectData , null , deviceBuildInfoDescriptor . outputPath ) ;
186
+ await this . $platformService . installApplication ( device , { release : false } , projectData , pathToBuildItem , deviceBuildInfoDescriptor . outputPath ) ;
184
187
}
185
188
}
186
189
@@ -319,7 +322,11 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
319
322
this . liveSyncProcessesInfo [ liveSyncData . projectDir ] . timer = timeoutTimer ;
320
323
} ;
321
324
322
- await this . $hooksService . executeBeforeHooks ( 'watch' ) ;
325
+ await this . $hooksService . executeBeforeHooks ( 'watch' , {
326
+ hookArgs : {
327
+ projectData
328
+ }
329
+ } ) ;
323
330
324
331
const watcherOptions : choki . WatchOptions = {
325
332
ignoreInitial : true ,
@@ -345,7 +352,10 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
345
352
filesToRemove . push ( filePath ) ;
346
353
}
347
354
348
- startTimeout ( ) ;
355
+ // Do not sync typescript files directly - wait for javascript changes to occur in order to restart the app only once
356
+ if ( path . extname ( filePath ) !== FileExtensions . TYPESCRIPT_FILE ) {
357
+ startTimeout ( ) ;
358
+ }
349
359
} ) ;
350
360
351
361
this . liveSyncProcessesInfo [ liveSyncData . projectDir ] . watcherInfo = { watcher, pattern } ;
0 commit comments