Skip to content

Commit f0115a3

Browse files
author
Mihail Slavchev
committed
Merge pull request #193 from NativeScript/slavchev/debug-command
2 parents 21f7d0b + a11ebd1 commit f0115a3

File tree

8 files changed

+114
-6
lines changed

8 files changed

+114
-6
lines changed

lib/bootstrap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ $injector.requireCommand("platform|add", "./commands/add-platform");
2525
$injector.requireCommand("platform|remove", "./commands/remove-platform");
2626
$injector.requireCommand("platform|update", "./commands/update-platform");
2727
$injector.requireCommand("run", "./commands/run");
28+
$injector.requireCommand("debug", "./commands/debug");
2829
$injector.requireCommand("prepare", "./commands/prepare");
2930
$injector.requireCommand("build", "./commands/build");
3031
$injector.requireCommand("deploy", "./commands/deploy");

lib/commands/debug.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
///<reference path="../.d.ts"/>
2+
"use strict";
3+
4+
import helpers = require("./../common/helpers");
5+
import util = require("util")
6+
7+
export class DebugCommand implements ICommand {
8+
constructor(private $platformService: IPlatformService,
9+
private $platformCommandParameter: ICommandParameter) { }
10+
11+
execute(args: string[]): IFuture<void> {
12+
return this.$platformService.debugPlatform(args[0]);
13+
}
14+
15+
allowedParameters = [this.$platformCommandParameter];
16+
}
17+
$injector.registerCommand("debug", DebugCommand);
18+

lib/declarations.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ interface IApplicationPackage {
2424
interface ILockFile {
2525
lock(): IFuture<void>;
2626
unlock(): IFuture<void>;
27-
}
27+
}
28+
29+
interface IOpener {
30+
open(target: string, appname: string): void;
31+
}

lib/definitions/platform.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ interface IPlatformService {
55
getPreparedPlatforms(): IFuture<string[]>;
66
removePlatforms(platforms: string[]): IFuture<void>;
77
updatePlatforms(platforms: string[]): IFuture<void>;
8-
runPlatform(platform: string): IFuture<void>;
8+
runPlatform(platform: string): IFuture<void>;
9+
debugPlatform(platform: string): IFuture<void>;
910
preparePlatform(platform: string): IFuture<void>;
1011
buildPlatform(platform: string): IFuture<void>;
1112
deployOnDevice(platform: string): IFuture<void>;

lib/services/platform-service.ts

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,60 @@ export class PlatformService implements IPlatformService {
177177
platform = platform.toLowerCase();
178178

179179
this.preparePlatform(platform).wait();
180-
if(options.emulator) {
180+
if (options.emulator) {
181181
this.deployOnEmulator(platform).wait();
182182
} else {
183183
this.deployOnDevice(platform).wait();
184184
}
185185
}).future<void>()();
186-
}
186+
}
187+
188+
public debugPlatform(platform: string): IFuture<void> {
189+
platform = platform.toLowerCase();
190+
191+
var ret = options.emulator
192+
? this.debugOnEmulator(platform)
193+
: this.debugOnDevice(platform);
194+
195+
return ret;
196+
}
197+
198+
public debugOnEmulator(platform: string): IFuture<void> {
199+
return (() => {
200+
201+
// a bit redundant
202+
this.deployOnEmulator(platform).wait();
203+
204+
this.debugOnDevice(platform).wait();
205+
}).future<void>()();
206+
}
207+
208+
public debugOnDevice(platform: string): IFuture<void> {
209+
return (() => {
210+
platform = platform.toLowerCase();
211+
212+
var packageFile = "";
213+
214+
if (options["debug-brk"]) {
215+
this.preparePlatform(platform).wait();
216+
217+
var platformData = this.$platformsData.getPlatformData(platform);
218+
219+
var cachedDeviceOption = options.device;
220+
options.device = true;
221+
this.buildPlatform(platform).wait();
222+
options.device = cachedDeviceOption;
223+
224+
packageFile = this.getLatestApplicationPackageForDevice(platformData).wait().packageName;
225+
this.$logger.out("Using ", packageFile);
226+
}
227+
228+
this.$devicesServices.initialize(platform, options.device).wait();
229+
var action = (device: Mobile.IDevice): IFuture<void> => { return device.debug(packageFile, this.$projectData.projectId); };
230+
this.$devicesServices.execute(action).wait();
231+
232+
}).future<void>()();
233+
}
187234

188235
public removePlatforms(platforms: string[]): IFuture<void> {
189236
return (() => {

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"node-uuid": "1.4.1",
4040
"npm": "1.4.26",
4141
"osenv": "0.1.0",
42+
"open": "0.0.4",
4243
"plistlib": "0.2.1",
4344
"progress-stream": "0.5.0",
4445
"prompt": "https://github.com/Icenium/prompt/tarball/master",
@@ -53,7 +54,8 @@
5354
"unzip": "0.1.9",
5455
"watchr": "2.4.11",
5556
"xmlhttprequest": "https://github.com/telerik/node-XMLHttpRequest/tarball/master",
56-
"yargs": "1.2.2"
57+
"yargs": "1.2.2",
58+
"node-inspector": "0.7.4"
5759
},
5860
"analyze": true,
5961
"devDependencies": {

resources/help.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ General commands:
2020
emulate Deploys the project in the native emulator for the selected target platform.
2121
run Runs your project on a connected device or in the native emulator, if configured.
2222
This is shorthand for prepare, build, and deploy.
23+
debug Debugs your project on a connected device or in the native emulator, if configured.
2324
device Lists all recognized connected physical or virtual device.
2425
feature-usage-tracking Configures anonymous feature usage tracking.
2526

@@ -235,6 +236,40 @@ Options:
235236

236237
--[/]--
237238

239+
--[debug]--
240+
241+
Usage:
242+
$ tns debug <Platform> [--device <Device ID>] [--debug-brk | --start | --stop | --get-port] [--debug-port <port>]
243+
$ nativescript debug <Platform> [--device <Device ID>] [--debug-brk | --start | --stop | --get-port] [--debug-port <port>]
244+
245+
Platform-specific usage:
246+
$ tns debug android --get-port
247+
$ tns debug android --debug-brk
248+
$ tns debug ios --debug-brk --debug-port 12345
249+
$ nativescript debug android --debug-brk
250+
$ nativescript debug ios --start --debug-port 12345
251+
252+
TODO: add proper help content
253+
254+
Debugs your project on a connected device or in the native emulator, if configured. This is shorthand for prepare, build, and deploy.
255+
<Device ID> is the index or name of the target device as listed by $ tns list-devices.
256+
257+
Before building for the Android emulator, verify that you have met the following requirements.
258+
You have added the file paths to the following directories from the Android SDK to your PATH environment variable.
259+
tools
260+
platform-tools
261+
You have created at least one device with the Android Virtual Device manager.
262+
263+
Before building for the iOS simulator, verify that you have installed the ios-sim npm package.
264+
265+
Before building for iOS device, verify that you have configured a valid pair of certificate and provisioning profile on your OS X system.
266+
267+
Options:
268+
--device - Specifies a connected device on which to run the app.
269+
--emulator - If set, runs the app in the native emulator for the target platform, if configured.
270+
271+
--[/]--
272+
238273
--[emulate]--
239274

240275
Usage:

0 commit comments

Comments
 (0)