22"use strict" ;
33
44import androidLiveSyncServiceLib = require( "../common/mobile/android/android-livesync-service" ) ;
5- import usbLivesyncServiceBaseLib = require( "../common/services/usb-livesync-service-base " ) ;
5+ import constants = require( "../constants " ) ;
66import helpers = require( "../common/helpers" ) ;
7+ import usbLivesyncServiceBaseLib = require( "../common/services/usb-livesync-service-base" ) ;
78import path = require( "path" ) ;
89
910export class UsbLiveSyncService extends usbLivesyncServiceBaseLib . UsbLiveSyncServiceBase implements IUsbLiveSyncService {
@@ -22,20 +23,39 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
2223 $deviceAppDataFactory : Mobile . IDeviceAppDataFactory ,
2324 $logger : ILogger ,
2425 private $injector : IInjector ,
26+ private $platformService : IPlatformService ,
2527 $dispatcher : IFutureDispatcher ) {
2628 super ( $devicesServices , $mobileHelper , $localToDevicePathDataFactory , $logger , $options , $deviceAppDataFactory , $fs , $dispatcher ) ;
2729 }
2830
2931 public liveSync ( platform : string ) : IFuture < void > {
3032 return ( ( ) => {
31- this . $options . justlaunch = true ;
33+ platform = this . initialize ( platform ) . wait ( ) ;
34+ this . $platformService . preparePlatform ( platform ) . wait ( ) ;
35+
36+ let platformData = this . $platformsData . getPlatformData ( platform . toLowerCase ( ) ) ;
37+ let projectFilesPath = path . join ( platformData . appDestinationDirectoryPath , constants . APP_FOLDER_NAME ) ;
3238
3339 let restartAppOnDeviceAction = ( device : Mobile . IDevice , deviceAppData : Mobile . IDeviceAppData , localToDevicePaths ?: Mobile . ILocalToDevicePathData [ ] ) : IFuture < void > => {
3440 let platformSpecificUsbLiveSyncService = this . resolveUsbLiveSyncService ( platform || this . $devicesServices . platform , device ) ;
3541 return platformSpecificUsbLiveSyncService . restartApplication ( deviceAppData , localToDevicePaths ) ;
3642 }
3743
38- this . sync ( platform , this . $projectData . projectId , this . $projectData . projectDir , path . join ( this . $projectData . projectDir , "app" ) , this . excludedProjectDirsAndFiles , restartAppOnDeviceAction ) . wait ( ) ;
44+ let notInstalledAppOnDeviceAction = ( device : Mobile . IDevice ) : IFuture < void > => {
45+ return this . $platformService . deployOnDevice ( platform ) ;
46+ }
47+
48+ let beforeBatchLiveSyncAction = ( filePath : string ) : IFuture < void > => {
49+ return ( ( ) => {
50+ if ( filePath . indexOf ( "node_modules" ) !== - 1 ) {
51+ this . $platformService . preparePlatform ( platform ) . wait ( ) ;
52+ }
53+ } ) . future < void > ( ) ( ) ;
54+ }
55+
56+ let watchGlob = this . $projectData . projectDir + "/**/*" ; //TODO: add node_modules folder
57+
58+ this . sync ( platform , this . $projectData . projectId , platformData . appDestinationDirectoryPath , projectFilesPath , this . excludedProjectDirsAndFiles , watchGlob , restartAppOnDeviceAction , notInstalledAppOnDeviceAction , beforeBatchLiveSyncAction ) . wait ( ) ;
3959 } ) . future < void > ( ) ( ) ;
4060 }
4161
@@ -81,19 +101,17 @@ export class AndroidUsbLiveSyncService extends androidLiveSyncServiceLib.Android
81101 let commands = [ this . liveSyncCommands . SyncFilesCommand ( ) ] ;
82102 this . livesync ( deviceAppData . appIdentifier , deviceAppData . deviceProjectRootPath , commands ) . wait ( ) ;
83103 } else {
84- // TODO: Introduce this.$mobileHelper.correctDevicePath(path: string) { return helpers.stringReplaceAll(path), '\\', '/') }
85- // Then later on this.$mobileHelper.buildDevicePath should call `correctDevicePath` before returning the output
86104 this . device . adb . executeShellCommand ( `chmod 0777 ${ this . $mobileHelper . buildDevicePath ( deviceAppData . deviceProjectRootPath , "app" ) } ` ) . wait ( ) ;
87105
88106 let commands : string [ ] = [ ] ;
89107
90108 let devicePathRoot = `/data/data/${ deviceAppData . appIdentifier } /files` ;
91109 _ . each ( localToDevicePaths , localToDevicePath => {
92- let devicePath = helpers . stringReplaceAll ( path . join ( devicePathRoot , localToDevicePath . getRelativeToProjectBasePath ( ) ) , '\\' , '/' ) ;
93- //commands.push(`ls "${path.dirname(devicePath)}" >/dev/null 2>/dev/null || mkdir "${path.dirname(devicePath)}"`);
110+ let devicePath = this . $mobileHelper . correctDevicePath ( path . join ( devicePathRoot , localToDevicePath . getRelativeToProjectBasePath ( ) ) ) ;
94111 commands . push ( `mv "${ localToDevicePath . getDevicePath ( ) } " "${ devicePath } "` ) ;
95112 } ) ;
96-
113+
114+ commands . push ( `rm -rf ${ this . $mobileHelper . buildDevicePath ( devicePathRoot , "code_cache" , "secondary_dexes" , "proxyThumb" ) } ` ) ;
97115 commands . push ( "exit" ) ;
98116
99117 let commandsFileDevicePath = this . $mobileHelper . buildDevicePath ( deviceAppData . deviceProjectRootPath , AndroidUsbLiveSyncService . LIVESYNC_COMMANDS_FILE_NAME ) ;
0 commit comments