import { ChildProcess } from 'child_process' ; import { EventEmitter } from 'events' ; import * as stream from 'stream' ; import { NativeScriptCli } from './nativeScriptCli' ; import * as scanner from './streamScanner' ; export interface IDebugResult { tnsProcess : ChildProcess ; tnsOutputEventEmitter : EventEmitter ; } export abstract class Project { private _appRoot : string ; private _cli : NativeScriptCli ; constructor ( appRoot , cli ) { this . _appRoot = appRoot ; this . _cli = cli ; } public get appRoot ( ) : string { return this . _appRoot ; } public get cli ( ) : NativeScriptCli { return this . _cli ; } public abstract platformName ( ) ; public run ( tnsArgs ? ) { return this . executeRunCommand ( tnsArgs ) ; } public abstract attach ( tnsArgs ? ) ; public abstract debug ( options , tnsArgs ? ) ; protected configureReadyEvent ( readableStream , eventEmitter ) { new scanner . StringMatchingScanner ( readableStream ) . onEveryMatch ( 'TypeScript compiler failed' , ( ) => { eventEmitter . emit ( 'tsCompilationError' ) ; } ) ; } protected executeRunCommand ( args ) { return this . _cli . execute ( [ 'run' , this . platformName ( ) ] . concat ( args ) , this . _appRoot ) ; } protected executeDebugCommand ( args ) { return this . _cli . execute ( [ 'debug' , this . platformName ( ) ] . concat ( args ) , this . _appRoot ) ; } protected executeTestCommand ( args ) { return this . _cli . execute ( [ 'test' , this . platformName ( ) ] . concat ( args ) , this . _appRoot ) ; } }