Skip to content

Commit 246adb0

Browse files
authored
Merge pull request #1871 from NativeScript/debug-command-and-service
Debug command and debug service improved
2 parents fddabef + f2299e9 commit 246adb0

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

lib/commands/debug.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export class DebugPlatformCommand implements ICommand {
22
constructor(private debugService: IDebugService,
33
private $devicesService: Mobile.IDevicesService,
4-
private $errors: IErrors,
4+
private $logger: ILogger,
55
protected $options: IOptions) { }
66

77
execute(args: string[]): IFuture<void> {
@@ -13,14 +13,16 @@
1313
canExecute(args: string[]): IFuture<boolean> {
1414
return ((): boolean => {
1515
this.$devicesService.initialize({ platform: this.debugService.platform, deviceId: this.$options.device }).wait();
16-
if(this.$options.emulator) {
16+
// Start emulator if --emulator is selected or no devices found.
17+
if(this.$options.emulator || this.$devicesService.deviceCount === 0) {
1718
return true;
1819
}
1920

20-
if(this.$devicesService.deviceCount === 0) {
21-
this.$errors.failWithoutHelp("No devices detected. Connect a device and try again.");
22-
} else if (this.$devicesService.deviceCount > 1) {
23-
this.$errors.fail("Cannot debug on multiple devices. Select device with --device option.");
21+
if (this.$devicesService.deviceCount > 1) {
22+
// Starting debugger on emulator.
23+
this.$options.emulator = true;
24+
25+
this.$logger.warn("Multiple devices found! Starting debugger on emulator. If you want to debug on specific device please select device with --device option.".yellow.bold);
2426
}
2527

2628
return true;
@@ -31,19 +33,19 @@
3133
export class DebugIOSCommand extends DebugPlatformCommand {
3234
constructor($iOSDebugService: IDebugService,
3335
$devicesService: Mobile.IDevicesService,
34-
$errors: IErrors,
36+
$logger: ILogger,
3537
$options: IOptions) {
36-
super($iOSDebugService, $devicesService, $errors, $options);
38+
super($iOSDebugService, $devicesService, $logger, $options);
3739
}
3840
}
3941
$injector.registerCommand("debug|ios", DebugIOSCommand);
4042

4143
export class DebugAndroidCommand extends DebugPlatformCommand {
4244
constructor($androidDebugService: IDebugService,
4345
$devicesService: Mobile.IDevicesService,
44-
$errors: IErrors,
46+
$logger: ILogger,
4547
$options: IOptions) {
46-
super($androidDebugService, $devicesService, $errors, $options);
48+
super($androidDebugService, $devicesService, $logger, $options);
4749
}
4850
}
4951
$injector.registerCommand("debug|android", DebugAndroidCommand);

lib/services/ios-debug-service.ts

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class IOSDebugService implements IDebugService {
4040
this.$errors.failWithoutHelp("Expected exactly one of the --debug-brk or --start options.");
4141
}
4242

43+
if (this.$devicesService.isOnlyiOSSimultorRunning() || this.$devicesService.deviceCount === 0) {
44+
this.$options.emulator = true;
45+
}
46+
4347
if (this.$options.emulator) {
4448
if (this.$options.debugBrk) {
4549
return this.emulatorDebugBrk(true);

0 commit comments

Comments
 (0)