-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathandroidProject.ts
62 lines (52 loc) · 2.84 KB
/
androidProject.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import {ChildProcess} from 'child_process';
import * as stream from 'stream';
import {EventEmitter} from 'events';
import {Project, DebugResult} from './project';
import * as scanner from './streamScanner';
import {Version} from '../common/version';
import {NativeScriptCli} from './nativeScriptCli';
export type GetDebugPortResult = { tnsProcess: ChildProcess, debugPort: Promise<number> };
export class AndroidProject extends Project {
constructor(appRoot: string, cli: NativeScriptCli) {
super(appRoot, cli);
}
public platformName(): string {
return "android";
}
public attach(tnsArgs?: string[]): DebugResult {
let args: string[] = ["--start"];
args = args.concat(tnsArgs);
let debugProcess : ChildProcess = super.executeDebugCommand(args);
let tnsOutputEventEmitter = new EventEmitter();
this.configureReadyEvent(debugProcess.stdout, tnsOutputEventEmitter, true);
return { tnsProcess: debugProcess, tnsOutputEventEmitter: tnsOutputEventEmitter };
}
public debug(options: { stopOnEntry: boolean, watch: boolean }, tnsArgs?: string[]): DebugResult {
let args: string[] = [];
args.push(options.watch ? "--watch" : "--no-watch");
if (options.stopOnEntry) { args.push("--debug-brk"); }
args = args.concat(tnsArgs);
let debugProcess : ChildProcess = super.executeDebugCommand(args);
let tnsOutputEventEmitter: EventEmitter = new EventEmitter();
this.configureReadyEvent(debugProcess.stdout, tnsOutputEventEmitter, false);
return { tnsProcess: debugProcess, tnsOutputEventEmitter: tnsOutputEventEmitter };
}
protected configureReadyEvent(readableStream: stream.Readable, eventEmitter: EventEmitter, attach?: boolean): void {
super.configureReadyEvent(readableStream, eventEmitter);
let debugPort = null;
new scanner.StringMatchingScanner(readableStream).onEveryMatch(new RegExp("device: .* debug port: [0-9]+"), (match: scanner.MatchFound) => {
//device: {device-name} debug port: {debug-port}
debugPort = parseInt((<string>match.matches[0]).match("(?:debug port: )([\\d]{5})")[1]);
if (attach) {
// 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); }, 500);
}
});
if (!attach) {
new scanner.StringMatchingScanner(readableStream).onEveryMatch('# NativeScript Debugger started #', (match: scanner.MatchFound) => {
// 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); }, 500);
});
}
}
}