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/Loader.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/Loader.purs')
-rw-r--r-- | src/PursLoader/Loader.purs | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/src/PursLoader/Loader.purs b/src/PursLoader/Loader.purs index e9e03c4..5373d2f 100644 --- a/src/PursLoader/Loader.purs +++ b/src/PursLoader/Loader.purs | |||
@@ -4,6 +4,8 @@ module PursLoader.Loader | |||
4 | , loaderFn | 4 | , loaderFn |
5 | ) where | 5 | ) where |
6 | 6 | ||
7 | import Prelude (Unit(), ($), (<>), (>>=), (<$>), (++), bind, flip, id, pure, return, unit) | ||
8 | |||
7 | import Control.Monad.Aff (Aff(), runAff) | 9 | import Control.Monad.Aff (Aff(), runAff) |
8 | import Control.Monad.Eff (Eff()) | 10 | import Control.Monad.Eff (Eff()) |
9 | import Control.Monad.Eff.Class (liftEff) | 11 | import Control.Monad.Eff.Class (liftEff) |
@@ -36,18 +38,11 @@ psciFilename = ".psci" | |||
36 | 38 | ||
37 | (!!!) = flip (!!) | 39 | (!!!) = flip (!!) |
38 | 40 | ||
39 | foreign import cwd "var cwd = process.cwd();" :: String | 41 | foreign import cwd :: String |
40 | 42 | ||
41 | foreign import relative """ | 43 | foreign import relative :: String -> String -> String |
42 | function relative(from) { | ||
43 | return function(to){ | ||
44 | var path = require('path'); | ||
45 | return path.relative(from, to); | ||
46 | }; | ||
47 | } | ||
48 | """ :: String -> String -> String | ||
49 | 44 | ||
50 | mkPsci :: [[String]] -> [[String]] -> String | 45 | mkPsci :: Array (Array String) -> Array (Array String) -> String |
51 | mkPsci srcs ffis = joinWith "\n" ((loadModule <$> concat srcs) <> (loadForeign <$> concat ffis)) | 46 | mkPsci srcs ffis = joinWith "\n" ((loadModule <$> concat srcs) <> (loadForeign <$> concat ffis)) |
52 | where | 47 | where |
53 | loadModule :: String -> String | 48 | loadModule :: String -> String |
@@ -56,7 +51,7 @@ mkPsci srcs ffis = joinWith "\n" ((loadModule <$> concat srcs) <> (loadForeign < | |||
56 | loadForeign :: String -> String | 51 | loadForeign :: String -> String |
57 | loadForeign a = ":f " ++ relative cwd a | 52 | loadForeign a = ":f " ++ relative cwd a |
58 | 53 | ||
59 | findFFI :: forall eff. [[String]] -> String -> Aff (fs :: FS | eff) (Maybe String) | 54 | findFFI :: forall eff. Array (Array String) -> String -> Aff (fs :: FS | eff) (Maybe String) |
60 | findFFI ffiss name = findFileUtf8 re (concat ffiss) | 55 | findFFI ffiss name = findFileUtf8 re (concat ffiss) |
61 | where | 56 | where |
62 | re = regex ("(?:^|\\n)//\\s*module\\s*" ++ name ++ "\\s*\\n") noFlags | 57 | re = regex ("(?:^|\\n)//\\s*module\\s*" ++ name ++ "\\s*\\n") noFlags |
@@ -79,7 +74,7 @@ loader' ref source = do | |||
79 | 74 | ||
80 | writeFileUtf8 psciFilename psciFile | 75 | writeFileUtf8 psciFilename psciFile |
81 | 76 | ||
82 | let moduleName = match moduleRegex source >>= (!!!) 1 | 77 | let moduleName = match moduleRegex source >>= (!!!) 1 >>= id |
83 | hasForeign = test foreignRegex source | 78 | hasForeign = test foreignRegex source |
84 | result = (\a -> "module.exports = require('" ++ a ++ "');") <$> moduleName | 79 | result = (\a -> "module.exports = require('" ++ a ++ "');") <$> moduleName |
85 | 80 | ||