]> git.immae.eu Git - github/fretlink/purs-loader.git/blobdiff - src/PursLoader/FS.purs
PureScript 0.7 updates and migration to pulp
[github/fretlink/purs-loader.git] / src / PursLoader / FS.purs
index 6955a632abbbd5beb79680b42bd5eb159917b10c..969e3d022dbf67abfe6422fbf0fb1e1ac9909de5 100644 (file)
@@ -4,6 +4,8 @@ module PursLoader.FS
   , findFileUtf8
   ) where
 
+import Prelude (Unit(), ($))
+
 import Control.Monad.Aff (Aff(), makeAff)
 import Control.Monad.Eff (Eff())
 import Control.Monad.Eff.Exception (Error())
@@ -18,50 +20,19 @@ foreign import data FS :: !
 writeFileUtf8 :: forall eff. String -> String -> Aff (fs :: FS | eff) Unit
 writeFileUtf8 filepath contents = makeAff $ runFn4 writeFileUtf8Fn filepath contents
 
-foreign import writeFileUtf8Fn """
-function writeFileUtf8Fn(filepath, contents, errback, callback) {
-  return function(){
-    var fs = require('fs');
-
-    fs.writeFile(filepath, contents, function(error){
-      if (error) errback(error)();
-      else callback()();
-    });
-  };
-}
-""" :: forall eff. Fn4 String
-                       String
-                       (Error -> Eff (fs :: FS | eff) Unit)
-                       (Unit -> Eff (fs :: FS | eff) Unit)
-                       (Eff (fs :: FS | eff) Unit)
+foreign import writeFileUtf8Fn :: forall eff. Fn4 String
+                                                  String
+                                                  (Error -> Eff (fs :: FS | eff) Unit)
+                                                  (Unit -> Eff (fs :: FS | eff) Unit)
+                                                  (Eff (fs :: FS | eff) Unit)
 
-findFileUtf8 :: forall eff. Regex -> [String] -> Aff (fs :: FS | eff) (Maybe String)
+findFileUtf8 :: forall eff. Regex -> Array String -> Aff (fs :: FS | eff) (Maybe String)
 findFileUtf8 regexp filepaths = makeAff $ runFn6 findFileUtf8Fn Nothing Just regexp filepaths
 
-foreign import findFileUtf8Fn """
-function findFileUtf8Fn(nothing, just, regex, filepaths, errback, callback) {
-  return function(){
-    var fs = require('fs');
-
-    var async = require('async');
-
-    function findFile(filepath, callback) {
-      fs.readFile(filepath, {encoding: 'utf-8'}, function(error, result){
-        if (error) callback(false);
-        else callback(regex.test(result));
-      });
-    }
-
-    async.detect(filepaths, findFile, function(result){
-      if (!result) callback(nothing)();
-      else callback(just(result))();
-    });
-  };
-}
-""" :: forall eff. Fn6 (Maybe String)
-                       (String -> Maybe String)
-                       Regex
-                       [String]
-                       (Error -> Eff (fs :: FS | eff) Unit)
-                       (Maybe String -> Eff (fs :: FS | eff) Unit)
-                       (Eff (fs :: FS | eff) Unit)
+foreign import findFileUtf8Fn :: forall eff. Fn6 (Maybe String)
+                                                 (String -> Maybe String)
+                                                 Regex
+                                                 (Array String)
+                                                 (Error -> Eff (fs :: FS | eff) Unit)
+                                                 (Maybe String -> Eff (fs :: FS | eff) Unit)
+                                                 (Eff (fs :: FS | eff) Unit)