import * as childProcess from 'child_process' import * as path from 'path' 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 { const dir = this.config.compileDir || 'exbuild' Logger.verb('tsc', 'transpile sources') Logger.verb('++', `tsc -p ${path.resolve(dir, this.tsconfigPath)}`) const tsc = childProcess.spawn('./node_modules/.bin/tsc', ['-p', path.resolve(dir, this.tsconfigPath)]) tsc.stdout.on('data', (output: Buffer) => { Logger.info('tsc', output.toString('utf-8')) }) tsc.stderr.on('data', (output: Buffer) => { Logger.error('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')) } }) }) } }