diff options
author | eric thul <thul.eric@gmail.com> | 2015-08-11 20:57:07 -0400 |
---|---|---|
committer | eric thul <thul.eric@gmail.com> | 2015-08-11 20:57:07 -0400 |
commit | 03b840cb5fb8ff5217fefc9e1240a3131db309fc (patch) | |
tree | 6183f4453aa15ad67ee0249fb8d35702cef5ecad /src/PursLoader/FS.purs | |
parent | fa01c5a4cb42d80ac147dc5ab512a0795dbe14da (diff) | |
download | purs-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.purs | 59 |
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 | ||
7 | import Prelude (Unit(), ($)) | ||
8 | |||
7 | import Control.Monad.Aff (Aff(), makeAff) | 9 | import Control.Monad.Aff (Aff(), makeAff) |
8 | import Control.Monad.Eff (Eff()) | 10 | import Control.Monad.Eff (Eff()) |
9 | import Control.Monad.Eff.Exception (Error()) | 11 | import Control.Monad.Eff.Exception (Error()) |
@@ -18,50 +20,19 @@ foreign import data FS :: ! | |||
18 | writeFileUtf8 :: forall eff. String -> String -> Aff (fs :: FS | eff) Unit | 20 | writeFileUtf8 :: forall eff. String -> String -> Aff (fs :: FS | eff) Unit |
19 | writeFileUtf8 filepath contents = makeAff $ runFn4 writeFileUtf8Fn filepath contents | 21 | writeFileUtf8 filepath contents = makeAff $ runFn4 writeFileUtf8Fn filepath contents |
20 | 22 | ||
21 | foreign import writeFileUtf8Fn """ | 23 | foreign import writeFileUtf8Fn :: forall eff. Fn4 String |
22 | function 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 | ||
38 | findFileUtf8 :: forall eff. Regex -> [String] -> Aff (fs :: FS | eff) (Maybe String) | 29 | findFileUtf8 :: forall eff. Regex -> Array String -> Aff (fs :: FS | eff) (Maybe String) |
39 | findFileUtf8 regexp filepaths = makeAff $ runFn6 findFileUtf8Fn Nothing Just regexp filepaths | 30 | findFileUtf8 regexp filepaths = makeAff $ runFn6 findFileUtf8Fn Nothing Just regexp filepaths |
40 | 31 | ||
41 | foreign import findFileUtf8Fn """ | 32 | foreign import findFileUtf8Fn :: forall eff. Fn6 (Maybe String) |
42 | function 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) | ||