index.js
function _readAllFiles(sDir = '', aWhitelist = []) {
  // read all files in current directory
  const aFiles = fs.readdirSync(sDir)

  // loop at all files
  const aContents = aFiles.reduce((aContents, sFileName) => {
    // get file stats
    const oFile = fs.statSync(`${sDir}/${sFileName}`)
    if (oFile.isDirectory()) {
      // append files of directory to list
      return aContents.concat(_readAllFiles(`${sDir}/${sFileName}`))
    }

    // append file content to list (if contained in whitelist)
    return aWhitelist.length === 0 || aWhitelist.indexOf(sFileName) !== -1
      ? aContents.concat(fs.readFileSync(`${sDir}/${sFileName}`, 'utf8'))
      : aContents
  }, [])

  return aContents
}
function _readAllFiles(sDir = '', aWhitelist = []) {
  // read all files in current directory
  const aFiles = fs.readdirSync(sDir)

  // loop at all files
  const aContents = aFiles.reduce((aContents, sFileName) => {
    // get file stats
    const oFile = fs.statSync(`${sDir}/${sFileName}`)
    if (oFile.isDirectory()) {
      // append files of directory to list
      return aContents.concat(_readAllFiles(`${sDir}/${sFileName}`))
    }

    // append file content to list (if contained in whitelist)
    return aWhitelist.length === 0 || aWhitelist.indexOf(sFileName) !== -1
      ? aContents.concat(fs.readFileSync(`${sDir}/${sFileName}`, 'utf8'))
      : aContents
  }, [])

  return aContents
}
function _readAllFiles ( sDir = '' , aWhitelist = [ ] ) { // read all files in current directory const aFiles = fs . readdirSync ( sDir ) // loop at all files const aContents = aFiles . reduce ( ( aContents , sFileName ) => { // get file stats const oFile = fs . statSync ( ` ${ sDir } ${ sFileName } ` ) if ( oFile . isDirectory ( ) ) { // append files of directory to list return aContents . concat ( _readAllFiles ( ` ${ sDir } ${ sFileName } ` ) ) } // append file content to list (if contained in whitelist) return aWhitelist . length === 0 || aWhitelist . indexOf ( sFileName ) !== - 1 ? aContents . concat ( fs . readFileSync ( ` ${ sDir } ${ sFileName } ` , 'utf8' ) ) : aContents } , [ ] ) return aContents }
Helper function to read directories recursively.
@param {string} [sDir] Directory.
@param {Array.string} [aWhitelist] List of file names as whitelist.
@returns {Array.string} List of read file contents.
Helper function to read directories recursively .