-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathiosProject.ts
66 lines (47 loc) · 2.29 KB
/
iosProject.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
63
64
65
66
import { ChildProcess } from 'child_process';
import { EventEmitter } from 'events';
import * as stream from 'stream';
import { NativeScriptCli } from './nativeScriptCli';
import { IDebugResult, Project } from './project';
import * as scanner from './streamScanner';
export class IosProject extends Project {
constructor(appRoot: string, cli: NativeScriptCli) {
super(appRoot, cli);
if (!this.isPlatformOSX()) {
throw new Error('iOS platform is supported only on OS X.');
}
}
public platformName(): string {
return 'ios';
}
public attach(tnsArgs?: string[]): IDebugResult {
let args: string[] = ['--start'];
args = args.concat(tnsArgs);
const debugProcess: ChildProcess = super.executeDebugCommand(args);
const tnsOutputEventEmitter: EventEmitter = new EventEmitter();
this.configureReadyEvent(debugProcess.stdout, tnsOutputEventEmitter);
return { tnsProcess: debugProcess, tnsOutputEventEmitter };
}
public debug(options: { stopOnEntry: boolean, watch: boolean, launchTests: boolean }, tnsArgs?: string[]): IDebugResult {
let args: string[] = [];
args.push(options.watch ? '--watch' : '--no-watch');
if (options.stopOnEntry) { args.push('--debug-brk'); }
args = args.concat(tnsArgs);
const debugProcess: ChildProcess = options.launchTests ?
super.executeTestCommand(args) : super.executeDebugCommand(args);
const tnsOutputEventEmitter: EventEmitter = new EventEmitter();
this.configureReadyEvent(debugProcess.stdout, tnsOutputEventEmitter);
return { tnsProcess: debugProcess, tnsOutputEventEmitter };
}
protected configureReadyEvent(readableStream: stream.Readable, eventEmitter: EventEmitter): void {
super.configureReadyEvent(readableStream, eventEmitter);
const streamScanner = new scanner.StringMatchingScanner(readableStream);
streamScanner.onEveryMatch(new RegExp('Opened localhost (.*)'), (match: scanner.IMatchFound) => {
const port = parseInt(match.matches[1] as string, 10);
setTimeout(() => { eventEmitter.emit('readyForConnection', port); }, 1000);
});
}
private isPlatformOSX(): boolean {
return /^darwin/.test(process.platform);
}
}