generated from garrettmills/template-npm-typescript
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
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<void> {
|
|
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.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'))
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|