aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/PursLoader/FS.purs
diff options
context:
space:
mode:
authoreric thul <thul.eric@gmail.com>2015-08-11 20:57:07 -0400
committereric thul <thul.eric@gmail.com>2015-08-11 20:57:07 -0400
commit03b840cb5fb8ff5217fefc9e1240a3131db309fc (patch)
tree6183f4453aa15ad67ee0249fb8d35702cef5ecad /src/PursLoader/FS.purs
parentfa01c5a4cb42d80ac147dc5ab512a0795dbe14da (diff)
downloadpurs-loader-03b840cb5fb8ff5217fefc9e1240a3131db309fc.tar.gz
purs-loader-03b840cb5fb8ff5217fefc9e1240a3131db309fc.tar.zst
purs-loader-03b840cb5fb8ff5217fefc9e1240a3131db309fc.zip
PureScript 0.7 updates and migration to pulp
Diffstat (limited to 'src/PursLoader/FS.purs')
-rw-r--r--src/PursLoader/FS.purs59
1 files changed, 15 insertions, 44 deletions
diff --git a/src/PursLoader/FS.purs b/src/PursLoader/FS.purs
index 6955a63..969e3d0 100644
--- a/src/PursLoader/FS.purs
+++ b/src/PursLoader/FS.purs
@@ -4,6 +4,8 @@ module PursLoader.FS
4 , findFileUtf8 4 , findFileUtf8
5 ) where 5 ) where
6 6
7import Prelude (Unit(), ($))
8
7import Control.Monad.Aff (Aff(), makeAff) 9import Control.Monad.Aff (Aff(), makeAff)
8import Control.Monad.Eff (Eff()) 10import Control.Monad.Eff (Eff())
9import Control.Monad.Eff.Exception (Error()) 11import Control.Monad.Eff.Exception (Error())
@@ -18,50 +20,19 @@ foreign import data FS :: !
18writeFileUtf8 :: forall eff. String -> String -> Aff (fs :: FS | eff) Unit 20writeFileUtf8 :: forall eff. String -> String -> Aff (fs :: FS | eff) Unit
19writeFileUtf8 filepath contents = makeAff $ runFn4 writeFileUtf8Fn filepath contents 21writeFileUtf8 filepath contents = makeAff $ runFn4 writeFileUtf8Fn filepath contents
20 22
21foreign import writeFileUtf8Fn """ 23foreign import writeFileUtf8Fn :: forall eff. Fn4 String
22function writeFileUtf8Fn(filepath, contents, errback, callback) { 24 String
23 return function(){ 25 (Error -> Eff (fs :: FS | eff) Unit)
24 var fs = require('fs'); 26 (Unit -> Eff (fs :: FS | eff) Unit)
25 27 (Eff (fs :: FS | eff) Unit)
26 fs.writeFile(filepath, contents, function(error){
27 if (error) errback(error)();
28 else callback()();
29 });
30 };
31}
32""" :: forall eff. Fn4 String
33 String
34 (Error -> Eff (fs :: FS | eff) Unit)
35 (Unit -> Eff (fs :: FS | eff) Unit)
36 (Eff (fs :: FS | eff) Unit)
37 28
38findFileUtf8 :: forall eff. Regex -> [String] -> Aff (fs :: FS | eff) (Maybe String) 29findFileUtf8 :: forall eff. Regex -> Array String -> Aff (fs :: FS | eff) (Maybe String)
39findFileUtf8 regexp filepaths = makeAff $ runFn6 findFileUtf8Fn Nothing Just regexp filepaths 30findFileUtf8 regexp filepaths = makeAff $ runFn6 findFileUtf8Fn Nothing Just regexp filepaths
40 31
41foreign import findFileUtf8Fn """ 32foreign import findFileUtf8Fn :: forall eff. Fn6 (Maybe String)
42function findFileUtf8Fn(nothing, just, regex, filepaths, errback, callback) { 33 (String -> Maybe String)
43 return function(){ 34 Regex
44 var fs = require('fs'); 35 (Array String)
45 36 (Error -> Eff (fs :: FS | eff) Unit)
46 var async = require('async'); 37 (Maybe String -> Eff (fs :: FS | eff) Unit)
47 38 (Eff (fs :: FS | eff) Unit)
48 function findFile(filepath, callback) {
49 fs.readFile(filepath, {encoding: 'utf-8'}, function(error, result){
50 if (error) callback(false);
51 else callback(regex.test(result));
52 });
53 }
54
55 async.detect(filepaths, findFile, function(result){
56 if (!result) callback(nothing)();
57 else callback(just(result))();
58 });
59 };
60}
61""" :: forall eff. Fn6 (Maybe String)
62 (String -> Maybe String)
63 Regex
64 [String]
65 (Error -> Eff (fs :: FS | eff) Unit)
66 (Maybe String -> Eff (fs :: FS | eff) Unit)
67 (Eff (fs :: FS | eff) Unit)