import fs = require ( "fs" ) ; import path = require ( "path" ) ; export default class FileSystem { param directory param includeDirectories returns static readdirRecursive ( searchDirectory , includeDirectories = false , isAbsolute = false ) { const result = [ ] ; if ( ! fs . lstatSync ( searchDirectory ) . isDirectory ( ) ) throw new Error ( `${ searchDirectory } is not a directory` ) ; ( function readdirRecursiveHandler ( directory ) : void { const files = fs . readdirSync ( directory ) ; files . forEach ( ( file ) => { let filepath ; if ( isAbsolute ) { filepath = path . resolve ( directory , file ) ; } else { filepath = path . join ( directory , file ) ; } if ( fs . lstatSync ( filepath ) . isDirectory ( ) ) { if ( includeDirectories ) { if ( isAbsolute ) { result . push ( path . resolve ( filepath ) ) ; } else { result . push ( path . relative ( searchDirectory , filepath ) ) ; } } readdirRecursiveHandler ( filepath ) ; } else { if ( isAbsolute ) { result . push ( path . resolve ( filepath ) ) ; } else { result . push ( path . relative ( searchDirectory , filepath ) ) ; } } } ) ; } ) ( searchDirectory ) ; return result ; } }