import * as childProcess from 'child_process' import {Phase} from './Phase' import {ExtolloCompileConfig} from '../types' import {Logger} from '../Logger' import {ExCompileError} from '../ExCompileError' export class CompilePhase extends Phase { constructor( config: ExtolloCompileConfig, tsconfig: any, protected readonly tsconfigPath: string, ) { super(config, tsconfig) } public run(): Promise { Logger.verb('tsc', 'transpile sources') const tsc = childProcess.spawn('tsc', ['-p', this.tsconfigPath]) tsc.stdout.on('data', (output: Buffer) => { Logger.info('tsc', output.toString('utf-8')) }) tsc.stderr.on('data', (output: Buffer) => { Logger.info('tsc', output.toString('utf-8')) }) return new Promise((res, rej) => { tsc.on('exit', code => { if ( code === 0 ) { res() } else { rej(new ExCompileError('Subprocess exited with non-zero exit code')) } }) }) } }