import util from "util" ; import fs from "fs" ; import path from "path" ; const readdir = util . promisify ( fs . readdir ) ; const stat = util . promisify ( fs . stat ) ; export interface IFileNameFormats { absolute : string ; relative : string ; } export default class FileSystemFolder { private name : string ; constructor ( name ) { this . name = name ; } public getName ( ) { return { relative : this . name , absolute : path . resolve ( this . name ) } ; } public async getFileNames ( ) { const fileNames = [ ] ; for ( const absoluteFileName of await this . getFileNamesRecursively ( this . name ) ) { fileNames . push ( { absolute : absoluteFileName , relative : absoluteFileName . replace ( path . resolve ( this . getName ( ) . absolute ) , "" ) . replace ( /\\/g , "/" ) } ) ; } return ( fileNames ) ; } ; private async getFileNamesRecursively ( name ) { const subdirs = await readdir ( name ) ; const files = await Promise . all ( subdirs . map ( async ( subdir ) => { const res = path . resolve ( name , subdir ) ; return ( await stat ( res ) ) . isDirectory ( ) ? this . getFileNamesRecursively ( res ) : res ; } ) ) ; return files . reduce ( ( a , f ) => a . concat ( f ) , [ ] ) ; } }