@@ -52,52 +52,6 @@ export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService {
52
52
} ) ;
53
53
}
54
54
55
- private async initializePreviewForDevice ( data : IPreviewAppLiveSyncData , device : Device ) : Promise < FilesPayload > {
56
- const filesToSyncMap : IDictionary < string [ ] > = { } ;
57
- const hmrData : IDictionary < IPlatformHmrData > = { } ;
58
- let promise = Promise . resolve < FilesPayload > ( null ) ;
59
- const startSyncFilesTimeout = async ( platform : string ) => {
60
- await promise
61
- . then ( async ( ) => {
62
- const currentHmrData = _ . cloneDeep ( hmrData ) ;
63
- const platformHmrData = currentHmrData [ platform ] || < any > { } ;
64
- const filesToSync = _ . cloneDeep ( filesToSyncMap [ platform ] ) ;
65
- // We don't need to prepare when webpack emits changed files. We just need to send a message to pubnub.
66
- promise = this . syncFilesForPlatformSafe ( data , platform , { filesToSync, skipPrepare : true , useHotModuleReload : data . appFilesUpdaterOptions . useHotModuleReload } ) ;
67
- await promise ;
68
-
69
- if ( data . appFilesUpdaterOptions . useHotModuleReload && platformHmrData . hash ) {
70
- const devices = _ . filter ( this . $previewSdkService . connectedDevices , { platform : platform . toLowerCase ( ) } ) ;
71
-
72
- await Promise . all ( _ . map ( devices , async ( previewDevice : Device ) => {
73
- const status = await this . $hmrStatusService . getHmrStatus ( previewDevice . id , platformHmrData . hash ) ;
74
- if ( status === HmrConstants . HMR_ERROR_STATUS ) {
75
- await this . syncFilesForPlatformSafe ( data , platform , { filesToSync : platformHmrData . fallbackFiles , useHotModuleReload : false , deviceId : previewDevice . id } ) ;
76
- }
77
- } ) ) ;
78
- }
79
- } ) ;
80
- filesToSyncMap [ platform ] = [ ] ;
81
- } ;
82
- await this . $hooksService . executeBeforeHooks ( "preview-sync" , {
83
- hookArgs : {
84
- projectData : this . $projectDataService . getProjectData ( data . projectDir ) ,
85
- hmrData,
86
- config : {
87
- env : data . env ,
88
- platform : device . platform ,
89
- appFilesUpdaterOptions : data . appFilesUpdaterOptions ,
90
- } ,
91
- externals : this . $previewAppPluginsService . getExternalPlugins ( device ) ,
92
- filesToSyncMap,
93
- startSyncFilesTimeout : startSyncFilesTimeout . bind ( this )
94
- }
95
- } ) ;
96
- await this . $previewAppPluginsService . comparePluginsOnDevice ( data , device ) ;
97
- const payloads = await this . syncFilesForPlatformSafe ( data , device . platform , { isInitialSync : true , useHotModuleReload : data . appFilesUpdaterOptions . useHotModuleReload } ) ;
98
- return payloads ;
99
- }
100
-
101
55
public async syncFiles ( data : IPreviewAppLiveSyncData , filesToSync : string [ ] , filesToRemove : string [ ] ) : Promise < void > {
102
56
this . showWarningsForNativeFiles ( filesToSync ) ;
103
57
@@ -119,6 +73,58 @@ export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService {
119
73
this . $previewSdkService . stop ( ) ;
120
74
}
121
75
76
+ private async initializePreviewForDevice ( data : IPreviewAppLiveSyncData , device : Device ) : Promise < FilesPayload > {
77
+ const hookArgs = this . getHookArgs ( data , device ) ;
78
+ await this . $hooksService . executeBeforeHooks ( "preview-sync" , { hookArgs } ) ;
79
+ await this . $previewAppPluginsService . comparePluginsOnDevice ( data , device ) ;
80
+ const payloads = await this . syncFilesForPlatformSafe ( data , device . platform , { isInitialSync : true , useHotModuleReload : data . appFilesUpdaterOptions . useHotModuleReload } ) ;
81
+ return payloads ;
82
+ }
83
+
84
+ private getHookArgs ( data : IPreviewAppLiveSyncData , device : Device ) {
85
+ const filesToSyncMap : IDictionary < string [ ] > = { } ;
86
+ const hmrData : IDictionary < IPlatformHmrData > = { } ;
87
+ const promise = Promise . resolve < FilesPayload > ( null ) ;
88
+ const result = {
89
+ projectData : this . $projectDataService . getProjectData ( data . projectDir ) ,
90
+ hmrData,
91
+ config : {
92
+ env : data . env ,
93
+ platform : device . platform ,
94
+ appFilesUpdaterOptions : data . appFilesUpdaterOptions ,
95
+ } ,
96
+ externals : this . $previewAppPluginsService . getExternalPlugins ( device ) ,
97
+ filesToSyncMap,
98
+ startSyncFilesTimeout : async ( platform : string ) => await this . onWebpackCompilationComplete ( data , hmrData , filesToSyncMap , promise , platform )
99
+ } ;
100
+
101
+ return result ;
102
+ }
103
+
104
+ private async onWebpackCompilationComplete ( data : IPreviewAppLiveSyncData , hmrData : IDictionary < IPlatformHmrData > , filesToSyncMap : IDictionary < string [ ] > , promise : Promise < FilesPayload > , platform : string ) {
105
+ await promise
106
+ . then ( async ( ) => {
107
+ const currentHmrData = _ . cloneDeep ( hmrData ) ;
108
+ const platformHmrData = currentHmrData [ platform ] || < any > { } ;
109
+ const filesToSync = _ . cloneDeep ( filesToSyncMap [ platform ] ) ;
110
+ // We don't need to prepare when webpack emits changed files. We just need to send a message to pubnub.
111
+ promise = this . syncFilesForPlatformSafe ( data , platform , { filesToSync, skipPrepare : true , useHotModuleReload : data . appFilesUpdaterOptions . useHotModuleReload } ) ;
112
+ await promise ;
113
+
114
+ if ( data . appFilesUpdaterOptions . useHotModuleReload && platformHmrData . hash ) {
115
+ const devices = _ . filter ( this . $previewSdkService . connectedDevices , { platform : platform . toLowerCase ( ) } ) ;
116
+
117
+ await Promise . all ( _ . map ( devices , async ( previewDevice : Device ) => {
118
+ const status = await this . $hmrStatusService . getHmrStatus ( previewDevice . id , platformHmrData . hash ) ;
119
+ if ( status === HmrConstants . HMR_ERROR_STATUS ) {
120
+ await this . syncFilesForPlatformSafe ( data , platform , { filesToSync : platformHmrData . fallbackFiles , useHotModuleReload : false , deviceId : previewDevice . id } ) ;
121
+ }
122
+ } ) ) ;
123
+ }
124
+ } ) ;
125
+ filesToSyncMap [ platform ] = [ ] ;
126
+ }
127
+
122
128
private async syncFilesForPlatformSafe ( data : IPreviewAppLiveSyncData , platform : string , opts ?: ISyncFilesOptions ) : Promise < FilesPayload > {
123
129
this . $logger . info ( `Start syncing changes for platform ${ platform } .` ) ;
124
130
0 commit comments