Skip to content

Commit 1649088

Browse files
authored
Merge pull request #1929 from NativeScript/raikov/livesync-debug
Added support for debug with livesync
2 parents e07b74a + 1dbb4c1 commit 1649088

File tree

8 files changed

+30
-8
lines changed

8 files changed

+30
-8
lines changed

lib/commands/debug.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
export class DebugPlatformCommand implements ICommand {
22
constructor(private debugService: IDebugService,
33
private $devicesService: Mobile.IDevicesService,
4+
private $usbLiveSyncService: ILiveSyncService,
45
private $logger: ILogger,
56
protected $options: IOptions) { }
67

78
execute(args: string[]): IFuture<void> {
9+
if (!this.$options.rebuild) {
10+
this.$options.debug = true;
11+
return this.$usbLiveSyncService.liveSync(this.$devicesService.platform);
12+
}
813
return this.debugService.debug();
914
}
1015

@@ -33,19 +38,21 @@
3338
export class DebugIOSCommand extends DebugPlatformCommand {
3439
constructor($iOSDebugService: IDebugService,
3540
$devicesService: Mobile.IDevicesService,
41+
$usbLiveSyncService: ILiveSyncService,
3642
$logger: ILogger,
3743
$options: IOptions) {
38-
super($iOSDebugService, $devicesService, $logger, $options);
44+
super($iOSDebugService, $devicesService, $usbLiveSyncService, $logger, $options);
3945
}
4046
}
4147
$injector.registerCommand("debug|ios", DebugIOSCommand);
4248

4349
export class DebugAndroidCommand extends DebugPlatformCommand {
4450
constructor($androidDebugService: IDebugService,
4551
$devicesService: Mobile.IDevicesService,
52+
$usbLiveSyncService: ILiveSyncService,
4653
$logger: ILogger,
4754
$options: IOptions) {
48-
super($androidDebugService, $devicesService, $logger, $options);
55+
super($androidDebugService, $devicesService, $usbLiveSyncService, $logger, $options);
4956
}
5057
}
5158
$injector.registerCommand("debug|android", DebugAndroidCommand);

lib/declarations.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ interface IOptions extends ICommonOptions {
9191
symlink: boolean;
9292
tnsModulesVersion: string;
9393
teamId: string;
94+
rebuild: boolean;
9495
}
9596

9697
interface IInitService {

lib/definitions/debug.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
interface IDebugService {
2-
debug(): IFuture<void>;
2+
debug(shouldBreak?: boolean): IFuture<void>;
33
debugStart(): IFuture<void>;
44
platform: string;
55
}

lib/options.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ export class Options extends commonOptionsLibPath.OptionsBase {
3636
tsc: {type: OptionType.Boolean },
3737
bundle: {type: OptionType.Boolean },
3838
all: {type: OptionType.Boolean },
39-
teamId: { type: OptionType.String }
39+
teamId: { type: OptionType.String },
40+
rebuild: { type: OptionType.Boolean, default: true }
4041
},
4142
path.join($hostInfo.isWindows ? process.env.AppData : path.join(osenv.home(), ".local/share"), ".nativescript-cli"),
4243
$errors, $staticConfig);

lib/services/android-debug-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ class AndroidDebugService implements IDebugService {
107107
if (!this.$options.start && !this.$options.emulator && !this.$options.getPort) {
108108
let cachedDeviceOption = this.$options.forDevice;
109109
this.$options.forDevice = true;
110-
this.$platformService.buildPlatform(this.platform).wait();
110+
if (this.$options.rebuild) {
111+
this.$platformService.buildPlatform(this.platform).wait();
112+
}
111113
this.$options.forDevice = !!cachedDeviceOption;
112114

113115
let platformData = this.$platformsData.getPlatformData(this.platform);

lib/services/ios-debug-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ class IOSDebugService implements IDebugService {
7373
private emulatorDebugBrk(shouldBreak?: boolean): IFuture<void> {
7474
return (() => {
7575
let platformData = this.$platformsData.getPlatformData(this.platform);
76-
this.$platformService.buildPlatform(this.platform).wait();
76+
if (this.$options.rebuild) {
77+
this.$platformService.buildPlatform(this.platform).wait();
78+
}
7779
let emulatorPackage = this.$platformService.getLatestApplicationPackageForEmulator(platformData).wait();
7880

7981
let args = shouldBreak ? "--nativescript-debug-brk" : "--nativescript-debug-start";

lib/services/livesync/android-livesync-service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ class AndroidLiveSyncService extends PlatformLiveSyncServiceBase<Mobile.IAndroid
1515
private $options: IOptions,
1616
private $injector: IInjector,
1717
private $projectData: IProjectData,
18+
private $androidDebugService: IDebugService,
1819
$liveSyncProvider: ILiveSyncProvider) {
1920
super(_device, $liveSyncProvider);
2021
}
2122

2223
public restartApplication(deviceAppData: Mobile.IDeviceAppData): IFuture<void> {
24+
if (this.$options.debug) {
25+
return this.$androidDebugService.debug();
26+
}
2327
return (() => {
2428
this.device.adb.executeShellCommand(["chmod", "777", deviceAppData.deviceProjectRootPath, `/data/local/tmp/${deviceAppData.appIdentifier}`]).wait();
2529

lib/services/livesync/ios-livesync-service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class IOSLiveSyncService extends PlatformLiveSyncServiceBase<Mobile.IiOSDevice>
1515
private $injector: IInjector,
1616
private $logger: ILogger,
1717
private $options: IOptions,
18+
private $iOSDebugService: IDebugService,
1819
$liveSyncProvider: ILiveSyncProvider) {
1920
super(_device, $liveSyncProvider);
2021
}
@@ -32,8 +33,12 @@ class IOSLiveSyncService extends PlatformLiveSyncServiceBase<Mobile.IiOSDevice>
3233
}
3334

3435
protected restartApplication(deviceAppData: Mobile.IDeviceAppData): IFuture<void> {
35-
let projectData: IProjectData = this.$injector.resolve("projectData");
36-
return this.device.applicationManager.restartApplication(deviceAppData.appIdentifier, projectData.projectName);
36+
if (this.$options.debug) {
37+
return this.$iOSDebugService.debug();
38+
} else {
39+
let projectData: IProjectData = this.$injector.resolve("projectData");
40+
return this.device.applicationManager.restartApplication(deviceAppData.appIdentifier, projectData.projectName);
41+
}
3742
}
3843

3944
protected reloadPage(deviceAppData: Mobile.IDeviceAppData): IFuture<void> {

0 commit comments

Comments
 (0)