import { join } from 'path' ; import copyFile from 'cp-file' ; import { existsSync } from 'fs' ; /**
 * Utility method to copy files
 */ export function copyFiles ( sourceBaseDir , destinationBaseDir , files , options ? ) { const overwrite = options ? options . overwrite : false ; return files . map ( ( file ) => { const absPath = join ( sourceBaseDir , file ) ; if ( ! existsSync ( absPath ) ) { throw new Error ( `Missing source file "${ absPath }"` ) ; } const targetAbsPath = join ( destinationBaseDir , file ) ; const hasTarget = existsSync ( targetAbsPath ) ; if ( hasTarget && ! overwrite ) { return { filePath : file , state : 'skipped' } ; } copyFile . sync ( absPath , targetAbsPath , { overwrite : true } ) ; return { filePath : file , state : 'copied' } ; } ) ; }