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.0 KiB
39 lines
1.0 KiB
2 years ago
|
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 => {
|
||
|
Logger.info('tsc', output)
|
||
|
})
|
||
|
|
||
|
tsc.stderr.on('data', output => {
|
||
|
Logger.info('tsc', output)
|
||
|
})
|
||
|
|
||
|
return new Promise((res, rej) => {
|
||
|
tsc.on('exit', code => {
|
||
|
if ( code === 0 ) {
|
||
|
res()
|
||
|
} else {
|
||
|
rej(new ExCompileError('Subprocess exited with non-zero exit code'))
|
||
|
}
|
||
|
})
|
||
|
})
|
||
|
}
|
||
|
}
|