import * as path from 'path' ; import fs from 'fs' ; import minimatch from 'minimatch' ; import debug from 'debug' ; const log = debug ( 'vcd:ext:glob' ) ; param root param directory param pattern const globReq = ( root , directory , pattern ) : string [ ] => { let filepaths = [ ] ; const files = fs . readdirSync ( directory ) ; for ( const filename of files ) { const filepath = path . join ( directory , filename ) ; const isDirectory = fs . statSync ( filepath ) . isDirectory ( ) ; const doesMatch = ! isDirectory && minimatch ( path . relative ( root , filepath ) , pattern , { matchBase : true } ) ; log ( `${ filepath }: isDirectory: ${ isDirectory }; doesMatch: ${ doesMatch }` ) ; if ( isDirectory ) { filepaths = filepaths . concat ( globReq ( root , filepath , pattern ) ) ; } else if ( doesMatch ) { filepaths . push ( filepath ) ; } } return filepaths ; } ; param directory param pattern export const glob = ( directory , pattern ) : string [ ] => { return globReq ( directory , directory , pattern ) ; } ;