@@ -2,6 +2,7 @@ import * as path from "path";
22import { Device , FilesPayload } from "nativescript-preview-sdk" ;
33import { APP_RESOURCES_FOLDER_NAME , APP_FOLDER_NAME } from "../../../constants" ;
44import { HmrConstants } from "../../../common/constants" ;
5+ import { stringify } from "../../../common/helpers" ;
56
67export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService {
78
@@ -30,7 +31,7 @@ export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService {
3031 return this . deviceInitializationPromise [ device . id ] ;
3132 }
3233
33- this . deviceInitializationPromise [ device . id ] = this . initializePreviewForDevice ( data , device ) ;
34+ this . deviceInitializationPromise [ device . id ] = this . getInitialFilesForDevice ( data , device ) ;
3435 try {
3536 const payloads = await this . deviceInitializationPromise [ device . id ] ;
3637 return payloads ;
@@ -62,18 +63,18 @@ export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService {
6263 this . $previewSdkService . stop ( ) ;
6364 }
6465
65- private async initializePreviewForDevice ( data : IPreviewAppLiveSyncData , device : Device ) : Promise < FilesPayload > {
66+ private async getInitialFilesForDevice ( data : IPreviewAppLiveSyncData , device : Device ) : Promise < FilesPayload > {
6667 const hookArgs = this . getHookArgs ( data , device ) ;
6768 await this . $hooksService . executeBeforeHooks ( "preview-sync" , { hookArgs } ) ;
6869 await this . $previewAppPluginsService . comparePluginsOnDevice ( data , device ) ;
69- const payloads = await this . syncInitialFilesForPlatformSafe ( data , device . platform ) ;
70+ const payloads = await this . getInitialFilesForPlatformSafe ( data , device . platform ) ;
7071 return payloads ;
7172 }
7273
7374 private getHookArgs ( data : IPreviewAppLiveSyncData , device : Device ) {
7475 const filesToSyncMap : IDictionary < string [ ] > = { } ;
7576 const hmrData : IDictionary < IPlatformHmrData > = { } ;
76- const promise = Promise . resolve < FilesPayload > ( null ) ;
77+ const promise = Promise . resolve ( ) ;
7778 const result = {
7879 projectData : this . $projectDataService . getProjectData ( data . projectDir ) ,
7980 hmrData,
@@ -94,32 +95,31 @@ export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService {
9495 return result ;
9596 }
9697
97- private async syncInitialFilesForPlatformSafe ( data : IPreviewAppLiveSyncData , platform : string ) : Promise < FilesPayload > {
98- this . $logger . info ( `Start syncing changes for platform ${ platform } .` ) ;
98+ private async getInitialFilesForPlatformSafe ( data : IPreviewAppLiveSyncData , platform : string ) : Promise < FilesPayload > {
99+ this . $logger . info ( `Start sending initial files for platform ${ platform } .` ) ;
99100
100101 try {
101102 const payloads = this . $previewAppFilesService . getInitialFilesPayload ( data , platform ) ;
102- this . $logger . info ( `Successfully synced changes for platform ${ platform } .` ) ;
103+ this . $logger . info ( `Successfully sent initial files for platform ${ platform } .` ) ;
103104 return payloads ;
104105 } catch ( err ) {
105- this . $logger . warn ( `Unable to apply changes for platform ${ platform } . Error is: ${ err } , ${ JSON . stringify ( err , null , 2 ) } . ` ) ;
106+ this . $logger . warn ( `Unable to apply changes for platform ${ platform } . Error is: ${ err } , ${ stringify ( err ) } ` ) ;
106107 }
107108 }
108109
109- private async syncFilesForPlatformSafe ( data : IPreviewAppLiveSyncData , filesData : IPreviewAppFilesData , platform : string , deviceId ?: string ) : Promise < FilesPayload > {
110+ private async syncFilesForPlatformSafe ( data : IPreviewAppLiveSyncData , filesData : IPreviewAppFilesData , platform : string , deviceId ?: string ) : Promise < void > {
110111 this . $logger . info ( `Start syncing changes for platform ${ platform } .` ) ;
111112
112113 try {
113114 const payloads = this . $previewAppFilesService . getFilesPayload ( data , filesData , platform ) ;
114115 await this . $previewSdkService . applyChanges ( payloads ) ;
115116 this . $logger . info ( `Successfully synced ${ payloads . files . map ( filePayload => filePayload . file . yellow ) } for platform ${ platform } .` ) ;
116- return payloads ;
117117 } catch ( err ) {
118- this . $logger . warn ( `Unable to apply changes for platform ${ platform } . Error is: ${ err } , ${ JSON . stringify ( err , null , 2 ) } .` ) ;
118+ this . $logger . warn ( `Unable to apply changes for platform ${ platform } . Error is: ${ err } , ${ stringify ( err ) } .` ) ;
119119 }
120120 }
121121
122- private async onWebpackCompilationComplete ( data : IPreviewAppLiveSyncData , hmrData : IDictionary < IPlatformHmrData > , filesToSyncMap : IDictionary < string [ ] > , promise : Promise < FilesPayload > , platform : string ) {
122+ private async onWebpackCompilationComplete ( data : IPreviewAppLiveSyncData , hmrData : IDictionary < IPlatformHmrData > , filesToSyncMap : IDictionary < string [ ] > , promise : Promise < void > , platform : string ) {
123123 await promise
124124 . then ( async ( ) => {
125125 const currentHmrData = _ . cloneDeep ( hmrData ) ;
0 commit comments