lib/helpers/sfs.js
function findAllFiles (baseDir, {
  ignoredFolders = [],
  maxDepth = undefined
} = {}) {
  let list = []

  function search (dir, depth) {
    fs.readdirSync(dir).forEach(file => {
      file = path.join(dir, file)

      // File or directory? Ok.
      // Otherwise, discard the file.
      let stat = fs.statSync(file)
      if (stat.isFile()) {
        list.push(file)
      } else if (stat.isDirectory()) {
        // The directory should be ignored?
        if (ignoredFolders.includes(path.basename(file))) {
          return
        }

        // Should we stop at this depth?
        if (maxDepth && (depth >= maxDepth)) {
          return
        }

        search(file, depth + 1)
      }
    })
  }

  search(baseDir, 0)

  return list
}
function findAllFiles (baseDir, {
  ignoredFolders = [],
  maxDepth = undefined
} = {}) {
  let list = []

  function search (dir, depth) {
    fs.readdirSync(dir).forEach(file => {
      file = path.join(dir, file)

      // File or directory? Ok.
      // Otherwise, discard the file.
      let stat = fs.statSync(file)
      if (stat.isFile()) {
        list.push(file)
      } else if (stat.isDirectory()) {
        // The directory should be ignored?
        if (ignoredFolders.includes(path.basename(file))) {
          return
        }

        // Should we stop at this depth?
        if (maxDepth && (depth >= maxDepth)) {
          return
        }

        search(file, depth + 1)
      }
    })
  }

  search(baseDir, 0)

  return list
}
function findAllFiles ( baseDir , { ignoredFolders = [ ] , maxDepth = undefined } = { } ) { let list = [ ] function search ( dir , depth ) { fs . readdirSync ( dir ) . forEach ( file => { file = path . join ( dir , file ) // File or directory? Ok. // Otherwise, discard the file. let stat = fs . statSync ( file ) if ( stat . isFile ( ) ) { list . push ( file ) } else if ( stat . isDirectory ( ) ) { // The directory should be ignored? if ( ignoredFolders . includes ( path . basename ( file ) ) ) { return } // Should we stop at this depth? if ( maxDepth && ( depth >= maxDepth ) ) { return } search ( file , depth + 1 ) } } ) } search ( baseDir , 0 ) return list }
Find all files in a directory structure.
Find all files in a directory structure .