aboutsummaryrefslogblamecommitdiffhomepage
path: root/src/Glob.purs
blob: 392d9e4012e7e9877cf2feab2100bcd18fd3ca6f (plain) (tree)
































                                                                      
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)