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 , cli ) { super ( appRoot , cli ) ; if ( ! this . isPlatformOSX ( ) ) { throw new Error ( 'iOS platform is supported only on OS X.' ) ; } } public platformName ( ) { return 'ios' ; } public attach ( tnsArgs ? ) { let args = [ '--start' ] ; args = args . concat ( tnsArgs ) ; const debugProcess = super . executeDebugCommand ( args ) ; const tnsOutputEventEmitter = new EventEmitter ( ) ; this . configureReadyEvent ( debugProcess . stdout , tnsOutputEventEmitter ) ; return { tnsProcess : debugProcess , tnsOutputEventEmitter } ; } public debug ( options , tnsArgs ? ) { let args = [ ] ; args . push ( options . watch ? '--watch' : '--no-watch' ) ; if ( options . stopOnEntry ) { args . push ( '--debug-brk' ) ; } args = args . concat ( tnsArgs ) ; const debugProcess = options . launchTests ? super . executeTestCommand ( args ) : super . executeDebugCommand ( args ) ; const tnsOutputEventEmitter = new EventEmitter ( ) ; this . configureReadyEvent ( debugProcess . stdout , tnsOutputEventEmitter ) ; return { tnsProcess : debugProcess , tnsOutputEventEmitter } ; } protected configureReadyEvent ( readableStream , eventEmitter ) { super . configureReadyEvent ( readableStream , eventEmitter ) ; const streamScanner = new scanner . StringMatchingScanner ( readableStream ) ; streamScanner . onEveryMatch ( new RegExp ( 'Opened localhost (.*)' ) , ( match ) => { const port = parseInt ( match . matches [ 1 ] as string , 10 ) ; setTimeout ( ( ) => { eventEmitter . emit ( 'readyForConnection' , port ) ; } , 1000 ) ; } ) ; } private isPlatformOSX ( ) { return /^darwin/ . test ( process . platform ) ; } }