|
1 | 1 | import { ChildProcess } from 'child_process'; |
2 | 2 | import { EventEmitter } from 'events'; |
| 3 | +import * as semver from 'semver'; |
3 | 4 | import * as stream from 'stream'; |
4 | 5 | import { NativeScriptCli } from './nativeScriptCli'; |
5 | 6 | import { IDebugResult, Project } from './project'; |
6 | 7 | import * as scanner from './streamScanner'; |
7 | 8 |
|
8 | 9 | export class AndroidProject extends Project { |
| 10 | + private cliVersion: string; |
9 | 11 |
|
10 | 12 | constructor(appRoot: string, cli: NativeScriptCli) { |
11 | 13 | super(appRoot, cli); |
| 14 | + this.cliVersion = cli.executeGetVersion(); |
12 | 15 | } |
13 | 16 |
|
14 | 17 | public platformName(): string { |
@@ -37,24 +40,26 @@ export class AndroidProject extends Project { |
37 | 40 |
|
38 | 41 | const debugProcess: ChildProcess = super.executeDebugCommand(args); |
39 | 42 | const tnsOutputEventEmitter: EventEmitter = new EventEmitter(); |
| 43 | + const shouldWaitAfterRestartMessage = semver.lt(semver.coerce(this.cliVersion), '5.1.0'); |
| 44 | + const waitForRestartMessage = shouldWaitAfterRestartMessage || args.indexOf('--debug-brk') > -1; |
40 | 45 |
|
41 | | - this.configureReadyEvent(debugProcess.stdout, tnsOutputEventEmitter, args.indexOf('--debug-brk') > -1); |
| 46 | + this.configureReadyEvent(debugProcess.stdout, tnsOutputEventEmitter, waitForRestartMessage); |
42 | 47 |
|
43 | 48 | return { tnsProcess: debugProcess, tnsOutputEventEmitter }; |
44 | 49 | } |
45 | 50 |
|
46 | | - protected configureReadyEvent(readableStream: stream.Readable, eventEmitter: EventEmitter, debugBrk?: boolean): void { |
| 51 | + protected configureReadyEvent(readableStream: stream.Readable, eventEmitter: EventEmitter, waitForRestartMessage?: boolean): void { |
47 | 52 | super.configureReadyEvent(readableStream, eventEmitter); |
48 | 53 | let debugPort = null; |
49 | 54 |
|
50 | 55 | new scanner.StringMatchingScanner(readableStream).onEveryMatch(new RegExp('device: .* debug port: [0-9]+'), (match: scanner.IMatchFound) => { |
51 | 56 | // device: {device-name} debug port: {debug-port} |
52 | 57 | debugPort = parseInt((match.matches[0] as string).match('(?:debug port: )([\\d]{5})')[1], 10); |
53 | | - if (!debugBrk) { |
| 58 | + if (!waitForRestartMessage) { |
54 | 59 | setTimeout(() => { eventEmitter.emit('readyForConnection', debugPort); }, 1000); |
55 | 60 | } |
56 | 61 | }); |
57 | | - if (debugBrk) { |
| 62 | + if (waitForRestartMessage) { |
58 | 63 | new scanner.StringMatchingScanner(readableStream).onEveryMatch('# NativeScript Debugger started #', (match: scanner.IMatchFound) => { |
59 | 64 | // wait a little before trying to connect, this gives a chance for adb to be able to connect to the debug socket |
60 | 65 | setTimeout(() => { eventEmitter.emit('readyForConnection', debugPort); }, 1000); |
|
0 commit comments