index.js
function (dir_path) {
  return fs.statAsync(dir_path)
    .call('isDirectory')
    .then(function (isDirectory) {
      if (isDirectory) {
        return fs.readdirAsync(dir_path)
          .map(function (file_name) {
            var file_path = dir_path + '/' + file_name;
            return fs.statAsync(file_path)
              .then(function (stat) {
                return {
                  isDirectory: stat.isDirectory(),
                  file_path: file_path
                }
              })
          })
          .reduce(function (files, file_item) {
            if (file_item.isDirectory) {
              return getFilesByDir(file_item.file_path)
                .then(function (subDirFiles) {
                  return files.concat(subDirFiles)
                })
            }
            files.push(file_item.file_path);
            return files
          }, [])
      }
      throw new Error('Please input a valid directory!');
    })
}
function (dir_path) {
  return fs.statAsync(dir_path)
    .call('isDirectory')
    .then(function (isDirectory) {
      if (isDirectory) {
        return fs.readdirAsync(dir_path)
          .map(function (file_name) {
            var file_path = dir_path + '/' + file_name;
            return fs.statAsync(file_path)
              .then(function (stat) {
                return {
                  isDirectory: stat.isDirectory(),
                  file_path: file_path
                }
              })
          })
          .reduce(function (files, file_item) {
            if (file_item.isDirectory) {
              return getFilesByDir(file_item.file_path)
                .then(function (subDirFiles) {
                  return files.concat(subDirFiles)
                })
            }
            files.push(file_item.file_path);
            return files
          }, [])
      }
      throw new Error('Please input a valid directory!');
    })
}
function ( dir_path ) { return fs . statAsync ( dir_path ) . call ( 'isDirectory' ) . then ( function ( isDirectory ) { if ( isDirectory ) { return fs . readdirAsync ( dir_path ) . map ( function ( file_name ) { var file_path = dir_path + '/' + file_name ; return fs . statAsync ( file_path ) . then ( function ( stat ) { return { isDirectory : stat . isDirectory ( ) , file_path : file_path } } ) } ) . reduce ( function ( files , file_item ) { if ( file_item . isDirectory ) { return getFilesByDir ( file_item . file_path ) . then ( function ( subDirFiles ) { return files . concat ( subDirFiles ) } ) } files . push ( file_item . file_path ) ; return files } , [ ] ) } throw new Error ( 'Please input a valid directory!' ) ; } ) }
get all file in a directory recursively
get all file in a directory recursively