11import * as path from "path" ;
22import * as choki from "chokidar" ;
33import { EventEmitter } from "events" ;
4- import { exported } from "../../common/decorators" ;
54import { hook } from "../../common/helpers" ;
5+ import { FileExtensions } from "../../common/constants" ;
66
77const LiveSyncEvents = {
88 liveSyncStopped : "liveSyncStopped" ,
@@ -30,8 +30,6 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
3030 super ( ) ;
3131 }
3232
33- // TODO: Add finishLivesync method in the platform specific services
34- @exported ( "liveSyncService" )
3533 @hook ( "liveSync" )
3634 public async liveSync ( deviceDescriptors : ILiveSyncDeviceInfo [ ] ,
3735 liveSyncData : ILiveSyncInfo ) : Promise < void > {
@@ -54,7 +52,6 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
5452 }
5553 }
5654
57- @exported ( "liveSyncService" )
5855 public async stopLiveSync ( projectDir : string , deviceIdentifiers ?: string [ ] , ) : Promise < void > {
5956 const liveSyncProcessInfo = this . liveSyncProcessesInfo [ projectDir ] ;
6057
@@ -91,7 +88,12 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
9188
9289 // Kill typescript watcher
9390 // 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+ } ) ;
9597
9698 this . emit ( LiveSyncEvents . liveSyncStopped , { projectDir } ) ;
9799 }
@@ -155,7 +157,10 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
155157 if ( preparedPlatforms . indexOf ( platform ) === - 1 ) {
156158 preparedPlatforms . push ( platform ) ;
157159 // 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 ) ;
159164 }
160165
161166 const rebuildInfo = _ . find ( rebuiltInformation , info => info . isEmulator === device . isEmulator && info . platform === platform ) ;
@@ -169,18 +174,16 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
169174
170175 // TODO: fix args cast to any
171176 const shouldBuild = await this . $platformService . shouldBuild ( platform , projectData , < any > { buildForDevice : ! device . isEmulator } , deviceBuildInfoDescriptor . outputPath ) ;
177+ let pathToBuildItem = null ;
172178 if ( shouldBuild ) {
173- const pathToBuildItem = await deviceBuildInfoDescriptor . buildAction ( ) ;
179+ pathToBuildItem = await deviceBuildInfoDescriptor . buildAction ( ) ;
174180 // Is it possible to return shouldBuild for two devices? What about android device and android emulator?
175181 rebuiltInformation . push ( { isEmulator : device . isEmulator , platform, pathToBuildItem } ) ;
176- await this . $platformService . installApplication ( device , { release : false } , projectData , pathToBuildItem , deviceBuildInfoDescriptor . outputPath ) ;
177-
178182 }
179183
180184 const shouldInstall = await this . $platformService . shouldInstall ( device , projectData , deviceBuildInfoDescriptor . outputPath ) ;
181185 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 ) ;
184187 }
185188 }
186189
@@ -319,7 +322,11 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
319322 this . liveSyncProcessesInfo [ liveSyncData . projectDir ] . timer = timeoutTimer ;
320323 } ;
321324
322- await this . $hooksService . executeBeforeHooks ( 'watch' ) ;
325+ await this . $hooksService . executeBeforeHooks ( 'watch' , {
326+ hookArgs : {
327+ projectData
328+ }
329+ } ) ;
323330
324331 const watcherOptions : choki . WatchOptions = {
325332 ignoreInitial : true ,
@@ -345,7 +352,10 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
345352 filesToRemove . push ( filePath ) ;
346353 }
347354
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+ }
349359 } ) ;
350360
351361 this . liveSyncProcessesInfo [ liveSyncData . projectDir ] . watcherInfo = { watcher, pattern } ;
0 commit comments