aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Glob.purs
blob: 7bc92122d673ce7a02ddb0f6c882a81d0450220b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module PursLoader.Glob
  ( Glob()
  , glob
  ) where

import Control.Monad.Aff (Aff(), makeAff)
import Control.Monad.Eff (Eff())
import Control.Monad.Eff.Exception (Error())

import Data.Function

foreign import data Glob :: !

glob :: forall eff. String -> Aff (glob :: Glob | eff) [String]
glob pattern = makeAff $ runFn3 globFn pattern

foreign import globFn """
function globFn(pattern, errback, callback) {
  return function(){
    var glob = require('glob');

    glob(pattern, function(e, data){
      if (e) errback(e)();
      else callback(data)();
    });
  };
}
""" :: forall eff. Fn3 String
                       (Error -> Eff (glob :: Glob | eff) Unit)
                       ([String] -> Eff (glob :: Glob | eff) Unit)
                       (Eff (glob :: Glob | eff) Unit)