import { promisify } from 'util' ; import flatten from 'lodash/flatten' ; const glob = promisify ( require ( 'glob' ) ) ; export const collectFileNames = async ( files ) : Promise < string [ ] > => Promise . all ( files . map ( async ( fileName ) => { let fileList = await glob ( fileName + '/**/*' , { nodir : true } ) ; if ( ! fileList || ! fileList . length ) { fileList = await glob ( fileName , { nodir : true } ) ; if ( ! fileList || ! fileList . length ) { throw new Error ( `No file with name '${ fileName }' found.` ) ; } } return fileList ; } ) ) . then ( ( results ) => flatten ( results ) ) ;