index.js 550 B

1234567891011121314151617181920212223242526272829
  1. var fs = require('fs')
  2. var path = require('path')
  3. module.exports = read
  4. function read(root, filter, files, prefix) {
  5. prefix = prefix || ''
  6. files = files || []
  7. filter = filter || noDotFiles
  8. var dir = path.join(root, prefix)
  9. if (!fs.existsSync(dir)) return files
  10. if (fs.statSync(dir).isDirectory())
  11. fs.readdirSync(dir)
  12. .filter(filter)
  13. .forEach(function (name) {
  14. read(root, filter, files, path.join(prefix, name))
  15. })
  16. else
  17. files.push(prefix)
  18. return files
  19. }
  20. function noDotFiles(x) {
  21. return x[0] !== '.'
  22. }