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.

43 lines
1.2 KiB

import * as fse from 'fs-extra'
import * as path from 'path'
import * as mkdirp from 'mkdirp'
import * as rimraf from 'rimraf'
import * as rfdc from 'rfdc'
import { Phase } from './Phase'
import { Logger } from '../Logger'
export class PreparePhase extends Phase {
public async run(): Promise<void> {
const dir = this.config.compileDir || 'exbuild'
Logger.verb('prepare', `remove ${dir}`)
await new Promise<void>((res, rej) => {
rimraf(dir, e => {
if ( e ) {
rej(e)
} else {
res()
}
})
})
Logger.verb('prepare', `create ${dir}`)
await mkdirp(dir)
for ( const src of this.tsconfig.include ) {
Logger.verb('prepare', `copy ${src}`)
await fse.copy(src, path.join(dir, src))
}
const tsconfig = rfdc()(this.tsconfig)
const outDir = tsconfig?.compilerOptions?.outDir || './lib'
if ( !tsconfig.compilerOptions ) {
tsconfig.compilerOptions = {}
}
tsconfig.compilerOptions.outDir = path.join('..', outDir)
fse.writeFileSync(path.join(dir, 'tsconfig.json'), JSON.stringify(tsconfig, undefined, 4))
}
}