mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Add fs.listAsync
This commit is contained in:
parent
93bef861df
commit
a5dcd71548
@ -127,3 +127,25 @@ describe "fs", ->
|
||||
it "returns the paths with the specified extensions", ->
|
||||
path = require.resolve('fixtures/css.css')
|
||||
expect(fs.list(fs.resolveOnLoadPath('fixtures'), ['.css'])).toEqual [path]
|
||||
describe ".listAsync(path, [extensions,] callback)", ->
|
||||
paths = null
|
||||
|
||||
it "calls the callback with the absolute paths of entries within the given directory", ->
|
||||
waitsFor (done) ->
|
||||
fs.listAsync project.getPath(), (err, result) ->
|
||||
paths = result
|
||||
done()
|
||||
runs ->
|
||||
expect(paths).toContain project.resolve('css.css')
|
||||
expect(paths).toContain project.resolve('coffee.coffee')
|
||||
expect(paths).toContain project.resolve('two-hundred.txt')
|
||||
|
||||
it "can filter the paths by an optional array of file extensions", ->
|
||||
waitsFor (done) ->
|
||||
fs.listAsync project.getPath(), ['css', '.coffee'], (err, result) ->
|
||||
paths = result
|
||||
done()
|
||||
runs ->
|
||||
expect(paths).toContain project.resolve('css.css')
|
||||
expect(paths).toContain project.resolve('coffee.coffee')
|
||||
expect(path).toMatch /(css|coffee)$/ for path in paths
|
||||
|
@ -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) =>
|
||||
|
Loading…
Reference in New Issue
Block a user