@@ -2,6 +2,7 @@ import * as path from "path";
22import { FilePayload , Device } from "nativescript-preview-sdk" ;
33import { PreviewSdkEventNames } from "./preview-app-constants" ;
44import { APP_FOLDER_NAME , APP_RESOURCES_FOLDER_NAME , TNS_MODULES_FOLDER_NAME } from "../../../constants" ;
5+ const isTextOrBinary = require ( 'istextorbinary' ) ;
56
67export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService {
78 private excludedFileExtensions = [ ".ts" , ".sass" , ".scss" , ".less" ] ;
@@ -83,12 +84,22 @@ export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService {
8384
8485 const payloads = filesToTransfer
8586 . map ( file => {
86- return {
87+ const filePayload : FilePayload = {
8788 event : PreviewSdkEventNames . CHANGE_EVENT_NAME ,
8889 file : path . relative ( platformsAppFolderPath , file ) ,
89- fileContents : this . $fs . readText ( file ) ,
90- binary : false
90+ binary : isTextOrBinary . isBinarySync ( file ) ,
91+ fileContents : ""
9192 } ;
93+
94+ if ( filePayload . binary ) {
95+ const bitmap = < string > this . $fs . readFile ( file ) ;
96+ const base64 = new Buffer ( bitmap ) . toString ( 'base64' ) ;
97+ filePayload . fileContents = base64 ;
98+ } else {
99+ filePayload . fileContents = this . $fs . readText ( file ) ;
100+ }
101+
102+ return filePayload ;
92103 } ) ;
93104
94105 return payloads ;
0 commit comments