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.

53 lines
1.4 KiB

import {Phase} from './Phase'
import {ExtolloCompileConfig} from '../types'
import * as fse from 'fs-extra'
import * as path from 'path'
import {Logger} from '../Logger'
export class NonSourcePhase extends Phase {
constructor(
config: ExtolloCompileConfig,
tsconfig: any,
protected readonly nonSourcePath: string,
) {
super(config, tsconfig)
}
async run(): Promise<void> {
const outDir = this.tsconfig?.compilerOptions?.outDir || './lib'
const source = this.nonSourcePath
let dest = path.join(outDir, source)
if ( this.shouldUp(source) ) {
const upLevel = path.join(outDir).split(path.sep).length
dest = path.join(
outDir,
source.split(path.sep)
.slice(upLevel)
.join(path.sep),
)
}
const destParentDir = path.join(dest, '..')
Logger.verb('non-source', 'ensure', destParentDir)
await fse.mkdirp(destParentDir)
Logger.verb('non-source', 'copy', source, '->', dest)
await fse.copy(source, dest)
}
public shouldUp(nonSourcePath: string): boolean {
if ( Array.isArray(this.tsconfig.include) ) {
for ( const sourcePath of this.tsconfig.include ) {
if ( nonSourcePath.startsWith(sourcePath) ) {
return true
}
}
}
return false
}
}