Add fs.listAsync

This commit is contained in:
Nathan Sobo
2013-03-20 18:43:13 -06:00
parent 93bef861df
commit a5dcd71548
2 changed files with 35 additions and 0 deletions

View File

@@ -93,6 +93,19 @@ module.exports =
@traverseTreeSync(rootPath, onPath, onPath)
paths
listAsync: (rootPath, rest...) ->
extensions = rest.shift() if rest.length > 1
done = rest.shift()
fs.readdir rootPath, (err, paths) =>
return done(err) if err
paths = @filterExtensions(paths, extensions) if extensions
paths = paths.map (path) => @join(rootPath, path)
done(null, paths)
filterExtensions: (paths, extensions) ->
extensions = extensions.map (ext) -> '.' + ext.replace(/^\./, '')
paths.filter (path) => _.include(extensions, @extension(path))
listTree: (rootPath) ->
paths = []
onPath = (path) =>