lib/utils/readDirDeep.js
/**
 * Read a folder and its subfolders recursively
 *
 * @param {string} folder The folder or subfolder to read
 * @param {string} prefix The relative path to the initial parent folder
 * @returns {Promise<Array>} A Promise providing a list of fs.Dirent objects
 */
Read a folder and its subfolders recursively
@param {string} folder The folder or subfolder to read
@param {string} prefix The relative path to the initial parent folder
@returns {Promise} A Promise providing a list of fs.Dirent objects
Read a folder and its subfolders recursively @param { string } folder The folder or subfolder to read @param { string } prefix The relative path to the initial parent folder @returns { Promise } A Promise providing a list of fs . Dirent objects
async function recursiveReadDir (folder, prefix = ``) {
  const entries = (await readdir(folder, { withFileTypes: true })).map(async entry => {
    if (entry.isDirectory()) {
      const nextFolder = path.join(folder, entry.name)
      const nextPrefix = path.join(prefix, entry.name)
      return recursiveReadDir(nextFolder, nextPrefix)
    } else {
      entry.name = path.join(prefix, entry.name)
      return [entry]
    }
  })
  return (await Promise.all(entries)).flat()
}
async function recursiveReadDir ( folder , prefix = ` ` ) { const entries = ( await readdir ( folder , { withFileTypes : true } ) ) . map ( async entry => { if ( entry . isDirectory ( ) ) { const nextFolder = path . join ( folder , entry . name ) const nextPrefix = path . join ( prefix , entry . name ) return recursiveReadDir ( nextFolder , nextPrefix ) } else { entry . name = path . join ( prefix , entry . name ) return [ entry ] } } ) return ( await Promise . all ( entries ) ) . flat ( ) }
Read a folder and its subfolders recursively
 @param {string} folder The folder or subfolder to read
 @param {string} prefix The relative path to the initial parent folder
 @returns {Promise<Array>} A Promise providing a list of fs.Dirent objects
Read a folder and its subfolders recursively @param { string } folder The folder or subfolder to read @param { string } prefix The relative path to the initial parent folder @returns { Promise<Array > } A Promise providing a list of fs . Dirent objects