Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@types/lodash": "^4.14.109",
"@types/mocha": "^5.2.1",
"@types/node": "6.0.46",
"@types/semver": "^5.5.0",
"@types/universal-analytics": "0.4.1",
"cpx": "^1.5.0",
"mocha": "^5.2.0",
Expand Down
13 changes: 9 additions & 4 deletions src/project/androidProject.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { ChildProcess } from 'child_process';
import { EventEmitter } from 'events';
import * as semver from 'semver';
import * as stream from 'stream';
import { NativeScriptCli } from './nativeScriptCli';
import { IDebugResult, Project } from './project';
import * as scanner from './streamScanner';

export class AndroidProject extends Project {
private cliVersion: string;

constructor(appRoot: string, cli: NativeScriptCli) {
super(appRoot, cli);
this.cliVersion = cli.executeGetVersion();
}

public platformName(): string {
Expand Down Expand Up @@ -37,24 +40,26 @@ export class AndroidProject extends Project {

const debugProcess: ChildProcess = super.executeDebugCommand(args);
const tnsOutputEventEmitter: EventEmitter = new EventEmitter();
const shouldWaitAfterRestartMessage = semver.lt(semver.coerce(this.cliVersion), '5.1.0');
const waitForRestartMessage = shouldWaitAfterRestartMessage || args.indexOf('--debug-brk') > -1;

this.configureReadyEvent(debugProcess.stdout, tnsOutputEventEmitter, args.indexOf('--debug-brk') > -1);
this.configureReadyEvent(debugProcess.stdout, tnsOutputEventEmitter, waitForRestartMessage);

return { tnsProcess: debugProcess, tnsOutputEventEmitter };
}

protected configureReadyEvent(readableStream: stream.Readable, eventEmitter: EventEmitter, debugBrk?: boolean): void {
protected configureReadyEvent(readableStream: stream.Readable, eventEmitter: EventEmitter, waitForRestartMessage?: boolean): void {
super.configureReadyEvent(readableStream, eventEmitter);
let debugPort = null;

new scanner.StringMatchingScanner(readableStream).onEveryMatch(new RegExp('device: .* debug port: [0-9]+'), (match: scanner.IMatchFound) => {
// device: {device-name} debug port: {debug-port}
debugPort = parseInt((match.matches[0] as string).match('(?:debug port: )([\\d]{5})')[1], 10);
if (!debugBrk) {
if (!waitForRestartMessage) {
setTimeout(() => { eventEmitter.emit('readyForConnection', debugPort); }, 1000);
}
});
if (debugBrk) {
if (waitForRestartMessage) {
new scanner.StringMatchingScanner(readableStream).onEveryMatch('# NativeScript Debugger started #', (match: scanner.IMatchFound) => {
// wait a little before trying to connect, this gives a chance for adb to be able to connect to the debug socket
setTimeout(() => { eventEmitter.emit('readyForConnection', debugPort); }, 1000);
Expand Down