diff options
author | eric <thul.eric@gmail.com> | 2015-07-06 23:58:28 -0400 |
---|---|---|
committer | eric <thul.eric@gmail.com> | 2015-07-06 23:58:28 -0400 |
commit | 1d771135e825feaa1fba5177b60796578766b240 (patch) | |
tree | a063817b17ee2df146228cf66c4205c2d80f05be /src/Glob.purs | |
parent | 4558c6cf7879207166b1cc013e2e8112f558bb1d (diff) | |
parent | 167c852f657b4746331c4f89e358a4a4876ced78 (diff) | |
download | purs-loader-1d771135e825feaa1fba5177b60796578766b240.tar.gz purs-loader-1d771135e825feaa1fba5177b60796578766b240.tar.zst purs-loader-1d771135e825feaa1fba5177b60796578766b240.zip |
Merge pull request #16 from ethul/topic/issue-11-and-14
Topic/issue 11 and 14
Diffstat (limited to 'src/Glob.purs')
-rw-r--r-- | src/Glob.purs | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/Glob.purs b/src/Glob.purs index 7bc9212..392d9e4 100644 --- a/src/Glob.purs +++ b/src/Glob.purs | |||
@@ -1,6 +1,6 @@ | |||
1 | module PursLoader.Glob | 1 | module PursLoader.Glob |
2 | ( Glob() | 2 | ( Glob() |
3 | , glob | 3 | , globAll |
4 | ) where | 4 | ) where |
5 | 5 | ||
6 | import Control.Monad.Aff (Aff(), makeAff) | 6 | import Control.Monad.Aff (Aff(), makeAff) |
@@ -11,21 +11,23 @@ import Data.Function | |||
11 | 11 | ||
12 | foreign import data Glob :: ! | 12 | foreign import data Glob :: ! |
13 | 13 | ||
14 | glob :: forall eff. String -> Aff (glob :: Glob | eff) [String] | 14 | globAll :: forall eff. [String] -> Aff (glob :: Glob | eff) [[String]] |
15 | glob pattern = makeAff $ runFn3 globFn pattern | 15 | globAll patterns = makeAff $ runFn3 globAllFn patterns |
16 | 16 | ||
17 | foreign import globFn """ | 17 | foreign import globAllFn """ |
18 | function globFn(pattern, errback, callback) { | 18 | function globAllFn(patterns, errback, callback) { |
19 | return function(){ | 19 | return function(){ |
20 | var glob = require('glob'); | 20 | var glob = require('glob'); |
21 | 21 | ||
22 | glob(pattern, function(e, data){ | 22 | var async = require('async'); |
23 | if (e) errback(e)(); | 23 | |
24 | else callback(data)(); | 24 | async.map(patterns, glob, function(error, result){ |
25 | if (error) errback(new Error(error))(); | ||
26 | else callback(result)(); | ||
25 | }); | 27 | }); |
26 | }; | 28 | }; |
27 | } | 29 | } |
28 | """ :: forall eff. Fn3 String | 30 | """ :: forall eff. Fn3 [String] |
29 | (Error -> Eff (glob :: Glob | eff) Unit) | 31 | (Error -> Eff (glob :: Glob | eff) Unit) |
30 | ([String] -> Eff (glob :: Glob | eff) Unit) | 32 | ([[String]] -> Eff (glob :: Glob | eff) Unit) |
31 | (Eff (glob :: Glob | eff) Unit) | 33 | (Eff (glob :: Glob | eff) Unit) |