import { spawn } from 'child_process' ; import { Config } from './configure' ; export async function serveAngularCli ( config ) { const args = configureArguments ( config ) ; const ngServe = spawn ( 'node' , args ) ; const write = ( handler , data ) => { const message = data . toString ( ) ; handler . write ( `[ng serve]: ${ message }\n` ) ; } ; ngServe . stdout . on ( 'data' , data => { write ( process . stdout , data ) ; } ) ; ngServe . stderr . on ( 'data' , data => { write ( process . stderr , data ) ; } ) ; return Promise . resolve ( ) ; } function configureArguments ( config ) { let args = [ config . angularCliPath , 'serve' , config . angularAppName ] ; const publicHost = `${ config . angularCliHost }:${ config . angularCliPort }` ; if ( ! config . angularAppName ) { throw new Error ( `Please provide Playground's appName in your angular-playground.json file.` ) ; } args . push ( `--host=${ config . angularCliHost }` ) ; args . push ( `--port=${ config . angularCliPort }` ) ; args . push ( `--publicHost=${ publicHost }` ) ; if ( config . angularCliAdditionalArgs ) { args = args . concat ( config . angularCliAdditionalArgs ) ; } return args ; }