Skip to content

Commit 40aa2db

Browse files
committed
PR comments
1 parent 139b4df commit 40aa2db

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

lib/commands/livesync.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@
44
export class LivesyncCommand implements ICommand {
55
constructor(private $logger: ILogger,
66
private $usbLiveSyncService: IUsbLiveSyncService,
7-
private $mobileHelper: Mobile.IMobileHelper) { }
7+
private $mobileHelper: Mobile.IMobileHelper,
8+
private $options: IOptions,
9+
private $errors: IErrors) { }
810

911
public execute(args: string[]): IFuture<void> {
12+
this.$options.justlaunch = true;
1013
return this.$usbLiveSyncService.liveSync(args[0]);
1114
}
1215

1316
public canExecute(args: string[]): IFuture<boolean> {
1417
return (() => {
18+
if(args.length >= 2) {
19+
this.$errors.fail("Invalid number of arguments.");
20+
}
21+
1522
let platform = args[0];
1623
if(platform) {
1724
return _.contains(this.$mobileHelper.platformNames, this.$mobileHelper.normalizePlatformName(platform));

lib/services/usb-livesync-service.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"use strict";
33

44
import androidLiveSyncServiceLib = require("../common/mobile/android/android-livesync-service");
5-
import usbLivesyncServiceBaseLib = require("../common/services/usb-livesync-service-base");
5+
import constants = require("../constants");
66
import helpers = require("../common/helpers");
7+
import usbLivesyncServiceBaseLib = require("../common/services/usb-livesync-service-base");
78
import path = require("path");
89

910
export 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

Comments
 (0)