aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/PursLoader/Glob.purs
blob: 392d9e4012e7e9877cf2feab2100bcd18fd3ca6f (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
32
33
module PursLoader.Glob
  ( Glob()
  , globAll
  ) 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 :: !

globAll :: forall eff. [String] -> Aff (glob :: Glob | eff) [[String]]
globAll patterns = makeAff $ runFn3 globAllFn patterns

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

    var async = require('async');

    async.map(patterns, glob, function(error, result){
      if (error) errback(new Error(error))();
      else callback(result)();
    });
  };
}
""" :: forall eff. Fn3 [String]
                       (Error -> Eff (glob :: Glob | eff) Unit)
                       ([[String]] -> Eff (glob :: Glob | eff) Unit)
                       (Eff (glob :: Glob | eff) Unit)