Skip to content

Commit 0173f1a

Browse files
author
Tsvetan Raikov
committed
Added support for debug with livesync
1 parent 9fef7c9 commit 0173f1a

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

lib/commands/debug.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
protected $options: IOptions) { }
66

77
execute(args: string[]): IFuture<void> {
8-
return this.debugService.debug();
8+
return this.debugService.debug(true, false);
99
}
1010

1111
allowedParameters: ICommandParameter[] = [];

lib/definitions/debug.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
interface IDebugService {
2-
debug(): IFuture<void>;
3-
debugStart(): IFuture<void>;
2+
debug(shouldBuild: boolean, shouldBreak: boolean): IFuture<void>;
3+
debugStart(shouldBuild: boolean): IFuture<void>;
44
platform: string;
55
}

lib/services/ios-debug-service.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class IOSDebugService implements IDebugService {
3535
return "ios";
3636
}
3737

38-
public debug(): IFuture<void> {
38+
public debug(shouldBuild: boolean): IFuture<void> {
3939
if (this.$options.debugBrk && this.$options.start) {
4040
this.$errors.failWithoutHelp("Expected exactly one of the --debug-brk or --start options.");
4141
}
@@ -46,37 +46,38 @@ class IOSDebugService implements IDebugService {
4646

4747
if (this.$options.emulator) {
4848
if (this.$options.debugBrk) {
49-
return this.emulatorDebugBrk(true);
49+
return this.emulatorDebugBrk(shouldBuild, true);
5050
} else if (this.$options.start) {
5151
return this.emulatorStart();
5252
} else {
53-
return this.emulatorDebugBrk();
53+
return this.emulatorDebugBrk(shouldBuild, false);
5454
}
5555
} else {
5656
if (this.$options.debugBrk) {
57-
return this.deviceDebugBrk(true);
57+
return this.deviceDebugBrk(shouldBuild, true);
5858
} else if (this.$options.start) {
5959
return this.deviceStart();
6060
} else {
6161
let deploy = this.$platformService.deployOnDevice(this.platform);
6262
deploy.wait();
63-
6463
return this.deviceStart();
6564
}
6665
}
6766
}
6867

69-
public debugStart(): IFuture<void> {
68+
public debugStart(shouldBuild: boolean): IFuture<void> {
7069
return (() => {
7170
this.$devicesService.initialize({ platform: this.platform, deviceId: this.$options.device }).wait();
72-
this.$devicesService.execute((device: Mobile.IiOSDevice) => device.isEmulator ? this.emulatorDebugBrk() : this.debugBrkCore(device)).wait();
71+
this.$devicesService.execute((device: Mobile.IiOSDevice) => device.isEmulator ? this.emulatorDebugBrk(shouldBuild, false) : this.debugBrkCore(device)).wait();
7372
}).future<void>()();
7473
}
7574

76-
private emulatorDebugBrk(shouldBreak?: boolean): IFuture<void> {
75+
private emulatorDebugBrk(shouldBuild: boolean, shouldBreak: boolean): IFuture<void> {
7776
return (() => {
7877
let platformData = this.$platformsData.getPlatformData(this.platform);
79-
this.$platformService.buildPlatform(this.platform).wait();
78+
if (shouldBuild) {
79+
this.$platformService.buildPlatform(this.platform).wait();
80+
}
8081
let emulatorPackage = this.$platformService.getLatestApplicationPackageForEmulator(platformData).wait();
8182

8283
let args = shouldBreak ? "--nativescript-debug-brk" : "--nativescript-debug-start";
@@ -112,12 +113,12 @@ class IOSDebugService implements IDebugService {
112113
}).future<void>()();
113114
}
114115

115-
private deviceDebugBrk(shouldBreak?: boolean): IFuture<void> {
116+
private deviceDebugBrk(shouldBuild: boolean, shouldBreak: boolean): IFuture<void> {
116117
return (() => {
117118
this.$devicesService.initialize({ platform: this.platform, deviceId: this.$options.device }).wait();
118119
this.$devicesService.execute((device: iOSDevice.IOSDevice) => (() => {
119120
if (device.isEmulator) {
120-
return this.emulatorDebugBrk(shouldBreak).wait();
121+
return this.emulatorDebugBrk(shouldBuild, shouldBreak).wait();
121122
}
122123
// we intentionally do not wait on this here, because if we did, we'd miss the AppLaunching notification
123124
let deploy = this.$platformService.deployOnDevice(this.platform);

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class IOSLiveSyncService extends liveSyncServiceBaseLib.LiveSyncServiceBase<Mobi
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 liveSyncServiceBaseLib.LiveSyncServiceBase<Mobi
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(false, false);
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> {

lib/services/test-execution-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class TestExecutionService implements ITestExecutionService {
6969
if (this.$options.debugBrk) {
7070
this.$logger.info('Starting debugger...');
7171
let debugService: IDebugService = this.$injector.resolve(`${platform}DebugService`);
72-
debugService.debugStart().wait();
72+
debugService.debugStart(true).wait();
7373
}
7474
blockingOperationFuture.return();
7575
} catch(err) {
@@ -124,7 +124,7 @@ class TestExecutionService implements ITestExecutionService {
124124
}
125125

126126
if(this.$options.debugBrk) {
127-
this.getDebugService(platform).debug().wait();
127+
this.getDebugService(platform).debug(true, false).wait();
128128
} else {
129129
this.liveSyncProject(platform).wait();
130130
}

0 commit comments

Comments
 (0)