diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/FS.purs | 35 | ||||
-rw-r--r-- | src/Glob.purs | 22 | ||||
-rw-r--r-- | src/Loader.purs | 126 | ||||
-rw-r--r-- | src/LoaderRef.purs | 25 | ||||
-rw-r--r-- | src/LoaderUtil.purs | 9 | ||||
-rw-r--r-- | src/OS.purs | 3 | ||||
-rw-r--r-- | src/Options.purs | 50 | ||||
-rw-r--r-- | src/Path.purs | 36 |
8 files changed, 100 insertions, 206 deletions
diff --git a/src/FS.purs b/src/FS.purs index 68fe2f9..a56fe26 100644 --- a/src/FS.purs +++ b/src/FS.purs | |||
@@ -1,7 +1,6 @@ | |||
1 | module PursLoader.FS | 1 | module PursLoader.FS |
2 | ( FS() | 2 | ( FS() |
3 | , readFileUtf8 | 3 | , writeFileUtf8 |
4 | , readFileUtf8Sync | ||
5 | ) where | 4 | ) where |
6 | 5 | ||
7 | import Control.Monad.Aff (Aff(), makeAff) | 6 | import Control.Monad.Aff (Aff(), makeAff) |
@@ -12,34 +11,22 @@ import Data.Function | |||
12 | 11 | ||
13 | foreign import data FS :: ! | 12 | foreign import data FS :: ! |
14 | 13 | ||
15 | readFileUtf8 :: forall eff. String -> Aff (fs :: FS | eff) String | 14 | writeFileUtf8 :: forall eff. String -> String -> Aff (fs :: FS | eff) Unit |
16 | readFileUtf8 filepath = makeAff $ runFn3 readFileUtf8Fn filepath | 15 | writeFileUtf8 filepath contents = makeAff $ runFn4 writeFileUtf8Fn filepath contents |
17 | 16 | ||
18 | readFileUtf8Sync :: forall eff. String -> Eff (fs :: FS | eff) String | 17 | foreign import writeFileUtf8Fn """ |
19 | readFileUtf8Sync filepath = readFileUtf8SyncFn filepath | 18 | function writeFileUtf8Fn(filepath, contents, errback, callback) { |
20 | |||
21 | foreign import readFileUtf8Fn """ | ||
22 | function readFileUtf8Fn(filepath, errback, callback) { | ||
23 | return function(){ | 19 | return function(){ |
24 | var fs = require('fs'); | 20 | var fs = require('fs'); |
25 | 21 | ||
26 | fs.readFile(filepath, 'utf-8', function(e, data){ | 22 | fs.writeFile(filepath, contents, function(error){ |
27 | if (e) errback(e)(); | 23 | if (error) errback(error)(); |
28 | else callback(data)(); | 24 | else callback()(); |
29 | }); | 25 | }); |
30 | }; | 26 | }; |
31 | } | 27 | } |
32 | """ :: forall eff. Fn3 String | 28 | """ :: forall eff. Fn4 String |
29 | String | ||
33 | (Error -> Eff (fs :: FS | eff) Unit) | 30 | (Error -> Eff (fs :: FS | eff) Unit) |
34 | (String -> Eff (fs :: FS | eff) Unit) | 31 | (Unit -> Eff (fs :: FS | eff) Unit) |
35 | (Eff (fs :: FS | eff) Unit) | 32 | (Eff (fs :: FS | eff) Unit) |
36 | |||
37 | foreign import readFileUtf8SyncFn """ | ||
38 | function readFileUtf8SyncFn(filepath) { | ||
39 | return function(){ | ||
40 | var fs = require('fs'); | ||
41 | |||
42 | return fs.readFileSync(filepath, {encoding: 'utf-8'}); | ||
43 | }; | ||
44 | } | ||
45 | """ :: forall eff. String -> (Eff (fs :: FS | eff) String) | ||
diff --git a/src/Glob.purs b/src/Glob.purs index 7bc9212..392d9e4 100644 --- a/src/Glob.purs +++ b/src/Glob.purs | |||
@@ -1,6 +1,6 @@ | |||
1 | module PursLoader.Glob | 1 | module PursLoader.Glob |
2 | ( Glob() | 2 | ( Glob() |
3 | , glob | 3 | , globAll |
4 | ) where | 4 | ) where |
5 | 5 | ||
6 | import Control.Monad.Aff (Aff(), makeAff) | 6 | import Control.Monad.Aff (Aff(), makeAff) |
@@ -11,21 +11,23 @@ import Data.Function | |||
11 | 11 | ||
12 | foreign import data Glob :: ! | 12 | foreign import data Glob :: ! |
13 | 13 | ||
14 | glob :: forall eff. String -> Aff (glob :: Glob | eff) [String] | 14 | globAll :: forall eff. [String] -> Aff (glob :: Glob | eff) [[String]] |
15 | glob pattern = makeAff $ runFn3 globFn pattern | 15 | globAll patterns = makeAff $ runFn3 globAllFn patterns |
16 | 16 | ||
17 | foreign import globFn """ | 17 | foreign import globAllFn """ |
18 | function globFn(pattern, errback, callback) { | 18 | function globAllFn(patterns, errback, callback) { |
19 | return function(){ | 19 | return function(){ |
20 | var glob = require('glob'); | 20 | var glob = require('glob'); |
21 | 21 | ||
22 | glob(pattern, function(e, data){ | 22 | var async = require('async'); |
23 | if (e) errback(e)(); | 23 | |
24 | else callback(data)(); | 24 | async.map(patterns, glob, function(error, result){ |
25 | if (error) errback(new Error(error))(); | ||
26 | else callback(result)(); | ||
25 | }); | 27 | }); |
26 | }; | 28 | }; |
27 | } | 29 | } |
28 | """ :: forall eff. Fn3 String | 30 | """ :: forall eff. Fn3 [String] |
29 | (Error -> Eff (glob :: Glob | eff) Unit) | 31 | (Error -> Eff (glob :: Glob | eff) Unit) |
30 | ([String] -> Eff (glob :: Glob | eff) Unit) | 32 | ([[String]] -> Eff (glob :: Glob | eff) Unit) |
31 | (Eff (glob :: Glob | eff) Unit) | 33 | (Eff (glob :: Glob | eff) Unit) |
diff --git a/src/Loader.purs b/src/Loader.purs index fedc424..872a51c 100644 --- a/src/Loader.purs +++ b/src/Loader.purs | |||
@@ -1,5 +1,5 @@ | |||
1 | module PursLoader.Loader | 1 | module PursLoader.Loader |
2 | ( LoaderEff() | 2 | ( Effects() |
3 | , loader | 3 | , loader |
4 | , loaderFn | 4 | , loaderFn |
5 | ) where | 5 | ) where |
@@ -9,113 +9,81 @@ import Control.Monad.Eff (Eff()) | |||
9 | import Control.Monad.Eff.Class (liftEff) | 9 | import Control.Monad.Eff.Class (liftEff) |
10 | import Control.Monad.Eff.Exception (error) | 10 | import Control.Monad.Eff.Exception (error) |
11 | 11 | ||
12 | import Data.Array ((!!), catMaybes, concat, filter, null) | 12 | import Data.Array ((!!), concat) |
13 | import Data.Foldable (foldl) | ||
14 | import Data.Function (Fn2(), mkFn2) | 13 | import Data.Function (Fn2(), mkFn2) |
15 | import Data.Maybe (Maybe(..), fromMaybe, maybe) | 14 | import Data.Maybe (Maybe(..), fromMaybe, maybe) |
16 | import Data.Set (Set(), empty, insert, member, toList, unions) | 15 | import Data.String (joinWith) |
17 | import Data.String (joinWith, split) | 16 | import Data.String.Regex (match, noFlags, regex) |
18 | import Data.String.Regex (Regex(), match, noFlags, regex) | ||
19 | import Data.StrMap (StrMap(), fromList, lookup) | ||
20 | import Data.Traversable (sequence) | ||
21 | import Data.Tuple.Nested (tuple2) | ||
22 | 17 | ||
23 | import PursLoader.ChildProcess (ChildProcess(), spawn) | 18 | import PursLoader.ChildProcess (ChildProcess(), spawn) |
24 | import PursLoader.FS (FS(), readFileUtf8, readFileUtf8Sync) | 19 | import PursLoader.FS (FS(), writeFileUtf8) |
25 | import PursLoader.Glob (Glob(), glob) | 20 | import PursLoader.Glob (Glob(), globAll) |
26 | import PursLoader.LoaderRef (LoaderRef(), Loader(), async, cacheable, clearDependencies, addDependency, query, resourcePath) | 21 | import PursLoader.LoaderRef (LoaderRef(), Loader(), async, cacheable, query) |
27 | import PursLoader.LoaderUtil (getRemainingRequest, parseQuery) | 22 | import PursLoader.LoaderUtil (parseQuery) |
28 | import PursLoader.OS (eol) | 23 | import PursLoader.Options (loaderFFIOption, loaderSrcOption, pscOptions) |
29 | import PursLoader.Options (loaderSrcOption, pscMakeOptions, pscMakeDefaultOutput, pscMakeOutputOption) | ||
30 | import PursLoader.Path (dirname, join, relative, resolve) | ||
31 | 24 | ||
32 | foreign import cwd "var cwd = process.cwd();" :: String | 25 | type Effects eff = (cp :: ChildProcess, fs :: FS, glob :: Glob, loader :: Loader | eff) |
33 | 26 | ||
34 | moduleRegex = regex "(?:^|\\n)module\\s+([\\w\\.]+)" noFlags { ignoreCase = true } | 27 | moduleRegex = regex "(?:^|\\n)module\\s+([\\w\\.]+)" noFlags { ignoreCase = true } |
35 | 28 | ||
36 | importRegex = regex "^\\s*import\\s+(?:qualified\\s+)?([\\w\\.]+)" noFlags { ignoreCase = true } | 29 | pscCommand = "psc" |
37 | |||
38 | bowerPattern = join [ "bower_components", "purescript-*", "src" ] | ||
39 | 30 | ||
40 | pscMakeCommand = "psc-make" | 31 | psciCommand = "psci" |
41 | 32 | ||
42 | indexFilename = "index.js" | 33 | psciFilename = ".psci" |
43 | 34 | ||
44 | (!!!) = flip (!!) | 35 | (!!!) = flip (!!) |
45 | 36 | ||
46 | pursPattern :: [String] -> String | 37 | foreign import cwd "var cwd = process.cwd();" :: String |
47 | pursPattern srcs = join [ "{" ++ joinWith "," ([ bowerPattern ] <> srcs) ++ "}" | ||
48 | , "**" | ||
49 | , "*.purs" | ||
50 | ] | ||
51 | |||
52 | type GraphModule = { file :: String, imports :: [String] } | ||
53 | 38 | ||
54 | type Graph = StrMap GraphModule | 39 | foreign import relative """ |
40 | function relative(from) { | ||
41 | return function(to){ | ||
42 | var path = require('path'); | ||
43 | return path.relative(from, to); | ||
44 | }; | ||
45 | } | ||
46 | """ :: String -> String -> String | ||
47 | |||
48 | mkPsci :: [[String]] -> [[String]] -> String | ||
49 | mkPsci srcs ffis = joinWith "\n" ((loadModule <$> concat srcs) <> (loadForeign <$> concat ffis)) | ||
50 | where | ||
51 | loadModule :: String -> String | ||
52 | loadModule a = ":m " ++ relative cwd a | ||
55 | 53 | ||
56 | mkGraph :: forall eff. [String] -> Eff (fs :: FS | eff) Graph | 54 | loadForeign :: String -> String |
57 | mkGraph files = (fromList <<< catMaybes) <$> sequence (parse <$> files) | 55 | loadForeign a = ":f " ++ relative cwd a |
58 | where parse file = do source <- readFileUtf8Sync file | ||
59 | let key = match moduleRegex source >>= (!!!) 1 | ||
60 | lines = split eol source | ||
61 | imports = catMaybes $ (\a -> match importRegex a >>= (!!!) 1) <$> lines | ||
62 | return $ (\a -> tuple2 a { file: file, imports: imports }) <$> key | ||
63 | 56 | ||
64 | mkDeps :: forall eff. String -> Graph -> [String] | 57 | loader' :: forall eff. LoaderRef -> String -> Aff (Effects eff) (Maybe String) |
65 | mkDeps key graph = toList $ go empty key | ||
66 | where | ||
67 | go :: Set String -> String -> Set String | ||
68 | go acc key = | ||
69 | let node = fromMaybe {file: "", imports: []} (lookup key graph) | ||
70 | uniq = filter (not <<< flip member acc) node.imports | ||
71 | acc' = foldl (flip insert) acc node.imports | ||
72 | in if null uniq | ||
73 | then acc' | ||
74 | else unions $ go acc' <$> uniq | ||
75 | |||
76 | addDeps :: forall eff. LoaderRef -> Graph -> [String] -> Eff (loader :: Loader | eff) Unit | ||
77 | addDeps ref graph deps = const unit <$> (sequence $ add <$> deps) | ||
78 | where add dep = let res = lookup dep graph | ||
79 | path = (\a -> resolve a.file) <$> res | ||
80 | in maybe (pure unit) (addDependency ref) path | ||
81 | |||
82 | type LoaderAff eff a = Aff (loader :: Loader, glob :: Glob, cp :: ChildProcess, fs :: FS | eff) a | ||
83 | |||
84 | loader' :: forall eff. LoaderRef -> String -> LoaderAff eff (Maybe String) | ||
85 | loader' ref source = do | 58 | loader' ref source = do |
86 | liftEff $ cacheable ref | 59 | liftEff $ cacheable ref |
87 | 60 | ||
88 | let request = getRemainingRequest ref | 61 | let parsed = parseQuery $ query ref |
89 | parsed = parseQuery $ query ref | 62 | srcs = fromMaybe [] (loaderSrcOption parsed) |
90 | srcs = loaderSrcOption parsed | 63 | ffis = fromMaybe [] (loaderFFIOption parsed) |
91 | opts = pscMakeOptions parsed | 64 | opts = pscOptions parsed |
92 | pattern = pursPattern $ fromMaybe [] srcs | 65 | |
93 | key = match moduleRegex source >>= (!!!) 1 | 66 | spawn pscCommand (srcs <> opts) |
94 | 67 | ||
95 | files <- glob pattern | 68 | srcss <- globAll srcs |
96 | graph <- liftEff $ mkGraph files | 69 | ffiss <- globAll ffis |
97 | 70 | ||
98 | let deps = fromMaybe [] $ flip mkDeps graph <$> key | 71 | let psciFile = mkPsci srcss ffiss |
99 | outputPath = fromMaybe pscMakeDefaultOutput $ pscMakeOutputOption parsed | ||
100 | indexPath = (\a -> join [ outputPath, a, indexFilename ]) <$> key | ||
101 | 72 | ||
102 | liftEff $ clearDependencies ref | 73 | writeFileUtf8 psciFilename psciFile |
103 | liftEff $ addDependency ref (resourcePath ref) | ||
104 | liftEff $ addDeps ref graph deps | ||
105 | 74 | ||
106 | spawn pscMakeCommand (opts <> files) | 75 | let moduleName = match moduleRegex source >>= (!!!) 1 |
107 | indexFile <- sequence $ readFileUtf8 <$> indexPath | 76 | result = (\a -> "module.exports = require('" ++ a ++ "');") <$> moduleName |
108 | return indexFile | ||
109 | 77 | ||
110 | type LoaderEff eff a = Eff (loader :: Loader, glob :: Glob, cp :: ChildProcess, fs :: FS | eff) a | 78 | return result |
111 | 79 | ||
112 | loader :: forall eff. LoaderRef -> String -> LoaderEff eff Unit | 80 | loader :: forall eff. LoaderRef -> String -> Eff (Effects eff) Unit |
113 | loader ref source = do | 81 | loader ref source = do |
114 | callback <- async ref | 82 | callback <- async ref |
115 | runAff (\e -> callback (Just e) "") | 83 | runAff (\e -> callback (Just e) "") |
116 | (maybe (callback (Just $ error "Loader has failed to run") "") | 84 | (maybe (callback (Just (error "Loader has failed to run")) "") |
117 | (callback Nothing)) | 85 | (callback Nothing)) |
118 | (loader' ref source) | 86 | (loader' ref source) |
119 | 87 | ||
120 | loaderFn :: forall eff. Fn2 LoaderRef String (LoaderEff eff Unit) | 88 | loaderFn :: forall eff. Fn2 LoaderRef String (Eff (Effects eff) Unit) |
121 | loaderFn = mkFn2 loader | 89 | loaderFn = mkFn2 loader |
diff --git a/src/LoaderRef.purs b/src/LoaderRef.purs index 2d62754..2567b1e 100644 --- a/src/LoaderRef.purs +++ b/src/LoaderRef.purs | |||
@@ -3,16 +3,12 @@ module PursLoader.LoaderRef | |||
3 | , Loader() | 3 | , Loader() |
4 | , async | 4 | , async |
5 | , cacheable | 5 | , cacheable |
6 | , clearDependencies | ||
7 | , resourcePath | ||
8 | , addDependency | ||
9 | , query | 6 | , query |
10 | ) where | 7 | ) where |
11 | 8 | ||
12 | import Control.Monad.Eff (Eff()) | 9 | import Control.Monad.Eff (Eff()) |
13 | import Control.Monad.Eff.Exception (Error()) | 10 | import Control.Monad.Eff.Exception (Error()) |
14 | 11 | ||
15 | import Data.Foreign (Foreign()) | ||
16 | import Data.Function (Fn3(), runFn3) | 12 | import Data.Function (Fn3(), runFn3) |
17 | import Data.Maybe (Maybe(), fromMaybe, isJust) | 13 | import Data.Maybe (Maybe(), fromMaybe, isJust) |
18 | 14 | ||
@@ -48,27 +44,6 @@ function cacheable(ref){ | |||
48 | }; | 44 | }; |
49 | }""" :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit | 45 | }""" :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit |
50 | 46 | ||
51 | foreign import clearDependencies """ | ||
52 | function clearDependencies(ref){ | ||
53 | return function(){ | ||
54 | return ref.clearDependencies(); | ||
55 | }; | ||
56 | }""" :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit | ||
57 | |||
58 | foreign import resourcePath """ | ||
59 | function resourcePath(ref){ | ||
60 | return ref.resourcePath; | ||
61 | }""" :: LoaderRef -> String | ||
62 | |||
63 | foreign import addDependency """ | ||
64 | function addDependency(ref){ | ||
65 | return function(dep){ | ||
66 | return function(){ | ||
67 | return ref.addDependency(dep); | ||
68 | }; | ||
69 | }; | ||
70 | }""" :: forall eff. LoaderRef -> String -> Eff (loader :: Loader | eff) Unit | ||
71 | |||
72 | foreign import query """ | 47 | foreign import query """ |
73 | function query(ref){ | 48 | function query(ref){ |
74 | return ref.query; | 49 | return ref.query; |
diff --git a/src/LoaderUtil.purs b/src/LoaderUtil.purs index f22be44..86be124 100644 --- a/src/LoaderUtil.purs +++ b/src/LoaderUtil.purs | |||
@@ -1,18 +1,11 @@ | |||
1 | module PursLoader.LoaderUtil | 1 | module PursLoader.LoaderUtil |
2 | ( getRemainingRequest | 2 | ( parseQuery |
3 | , parseQuery | ||
4 | ) where | 3 | ) where |
5 | 4 | ||
6 | import Data.Foreign (Foreign()) | 5 | import Data.Foreign (Foreign()) |
7 | 6 | ||
8 | import PursLoader.LoaderRef (LoaderRef()) | 7 | import PursLoader.LoaderRef (LoaderRef()) |
9 | 8 | ||
10 | foreign import getRemainingRequest """ | ||
11 | function getRemainingRequest(ref){ | ||
12 | var loaderUtils = require('loader-utils'); | ||
13 | return loaderUtils.getRemainingRequest(ref); | ||
14 | }""" :: LoaderRef -> String | ||
15 | |||
16 | foreign import parseQuery """ | 9 | foreign import parseQuery """ |
17 | function parseQuery(query){ | 10 | function parseQuery(query){ |
18 | var loaderUtils = require('loader-utils'); | 11 | var loaderUtils = require('loader-utils'); |
diff --git a/src/OS.purs b/src/OS.purs deleted file mode 100644 index 590c3d6..0000000 --- a/src/OS.purs +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | module PursLoader.OS (eol) where | ||
2 | |||
3 | foreign import eol "var eol = require('os').EOL;" :: String | ||
diff --git a/src/Options.purs b/src/Options.purs index c47bebc..51e9be5 100644 --- a/src/Options.purs +++ b/src/Options.purs | |||
@@ -1,17 +1,17 @@ | |||
1 | module PursLoader.Options | 1 | module PursLoader.Options |
2 | ( pscMakeOptions | 2 | ( pscOptions |
3 | , pscMakeDefaultOutput | ||
4 | , pscMakeOutputOption | ||
5 | , loaderSrcOption | 3 | , loaderSrcOption |
4 | , loaderFFIOption | ||
6 | ) where | 5 | ) where |
7 | 6 | ||
7 | import Data.Array (concat) | ||
8 | import Data.Either (either) | 8 | import Data.Either (either) |
9 | 9 | ||
10 | import Data.Foreign (Foreign(), F()) | 10 | import Data.Foreign (Foreign(), F()) |
11 | import Data.Foreign.Class (IsForeign, read, readProp) | 11 | import Data.Foreign.Class (IsForeign, read, readProp) |
12 | import Data.Foreign.NullOrUndefined (NullOrUndefined(), runNullOrUndefined) | 12 | import Data.Foreign.NullOrUndefined (NullOrUndefined(..), runNullOrUndefined) |
13 | 13 | ||
14 | import Data.Maybe (Maybe(..), maybe) | 14 | import Data.Maybe (Maybe(..), maybe, fromMaybe) |
15 | 15 | ||
16 | noPreludeOpt = "no-prelude" | 16 | noPreludeOpt = "no-prelude" |
17 | 17 | ||
@@ -29,9 +29,11 @@ commentsOpt = "comments" | |||
29 | 29 | ||
30 | noPrefixOpt = "no-prefix" | 30 | noPrefixOpt = "no-prefix" |
31 | 31 | ||
32 | requirePathOpt = "require-path" | ||
33 | |||
32 | srcOpt = "src" | 34 | srcOpt = "src" |
33 | 35 | ||
34 | pscMakeDefaultOutput = "output" | 36 | ffiOpt = "ffi" |
35 | 37 | ||
36 | newtype Options | 38 | newtype Options |
37 | = Options { noPrelude :: NullOrUndefined Boolean | 39 | = Options { noPrelude :: NullOrUndefined Boolean |
@@ -42,7 +44,9 @@ newtype Options | |||
42 | , comments :: NullOrUndefined Boolean | 44 | , comments :: NullOrUndefined Boolean |
43 | , output :: NullOrUndefined String | 45 | , output :: NullOrUndefined String |
44 | , noPrefix :: NullOrUndefined Boolean | 46 | , noPrefix :: NullOrUndefined Boolean |
47 | , requirePath :: NullOrUndefined String | ||
45 | , src :: NullOrUndefined [String] | 48 | , src :: NullOrUndefined [String] |
49 | , ffi :: NullOrUndefined [String] | ||
46 | } | 50 | } |
47 | 51 | ||
48 | instance isForeignOptions :: IsForeign Options where | 52 | instance isForeignOptions :: IsForeign Options where |
@@ -54,7 +58,9 @@ instance isForeignOptions :: IsForeign Options where | |||
54 | , comments: _ | 58 | , comments: _ |
55 | , output: _ | 59 | , output: _ |
56 | , noPrefix: _ | 60 | , noPrefix: _ |
61 | , requirePath: _ | ||
57 | , src: _ | 62 | , src: _ |
63 | , ffi: _ | ||
58 | } <$> readProp noPreludeOpt obj | 64 | } <$> readProp noPreludeOpt obj |
59 | <*> readProp noOptsOpt obj | 65 | <*> readProp noOptsOpt obj |
60 | <*> readProp noMagicDoOpt obj | 66 | <*> readProp noMagicDoOpt obj |
@@ -63,26 +69,25 @@ instance isForeignOptions :: IsForeign Options where | |||
63 | <*> readProp commentsOpt obj | 69 | <*> readProp commentsOpt obj |
64 | <*> readProp outputOpt obj | 70 | <*> readProp outputOpt obj |
65 | <*> readProp noPrefixOpt obj | 71 | <*> readProp noPrefixOpt obj |
66 | <*> readProp srcOpt obj) | 72 | <*> readProp requirePathOpt obj |
73 | <*> readProp srcOpt obj | ||
74 | <*> readProp ffiOpt obj) | ||
67 | 75 | ||
68 | class LoaderOption a where | 76 | class LoaderOption a where |
69 | opt :: String -> NullOrUndefined a -> [String] | 77 | opt :: String -> NullOrUndefined a -> [String] |
70 | 78 | ||
71 | instance booleanLoaderOption :: LoaderOption Boolean where | 79 | instance booleanLoaderOption :: LoaderOption Boolean where |
72 | opt key opt = maybe [] (\a -> if a then ["--" ++ key] else []) | 80 | opt key val = maybe [] (\a -> if a then ["--" ++ key] else []) (runNullOrUndefined val) |
73 | (runNullOrUndefined opt) | ||
74 | 81 | ||
75 | instance stringLoaderOption :: LoaderOption String where | 82 | instance stringLoaderOption :: LoaderOption String where |
76 | opt key opt = maybe [] (\a -> ["--" ++ key ++ "=" ++ a]) | 83 | opt key val = maybe [] (\a -> ["--" ++ key ++ "=" ++ a]) (runNullOrUndefined val) |
77 | (runNullOrUndefined opt) | ||
78 | 84 | ||
79 | pscMakeOutputOption :: Foreign -> Maybe String | 85 | instance arrayLoaderOption :: (LoaderOption a) => LoaderOption [a] where |
80 | pscMakeOutputOption query = either (const Nothing) | 86 | opt key val = concat (opt key <$> (NullOrUndefined <<< Just) |
81 | (\(Options a) -> runNullOrUndefined a.output) | 87 | <$> (fromMaybe [] (runNullOrUndefined val))) |
82 | (read query) | ||
83 | 88 | ||
84 | pscMakeOptions :: Foreign -> [String] | 89 | pscOptions :: Foreign -> [String] |
85 | pscMakeOptions query = either (const []) fold parsed | 90 | pscOptions query = either (const []) fold parsed |
86 | where parsed = read query :: F Options | 91 | where parsed = read query :: F Options |
87 | fold (Options a) = opt noPreludeOpt a.noPrelude <> | 92 | fold (Options a) = opt noPreludeOpt a.noPrelude <> |
88 | opt noOptsOpt a.noOpts <> | 93 | opt noOptsOpt a.noOpts <> |
@@ -91,9 +96,12 @@ pscMakeOptions query = either (const []) fold parsed | |||
91 | opt verboseErrorsOpt a.verboseErrors <> | 96 | opt verboseErrorsOpt a.verboseErrors <> |
92 | opt commentsOpt a.comments <> | 97 | opt commentsOpt a.comments <> |
93 | opt outputOpt a.output <> | 98 | opt outputOpt a.output <> |
94 | opt noPrefixOpt a.noPrefix | 99 | opt noPrefixOpt a.noPrefix <> |
100 | opt requirePathOpt a.requirePath <> | ||
101 | opt ffiOpt a.ffi | ||
95 | 102 | ||
96 | loaderSrcOption :: Foreign -> Maybe [String] | 103 | loaderSrcOption :: Foreign -> Maybe [String] |
97 | loaderSrcOption query = either (const Nothing) | 104 | loaderSrcOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.src) (read query) |
98 | (\(Options a) -> runNullOrUndefined a.src) | 105 | |
99 | (read query) | 106 | loaderFFIOption :: Foreign -> Maybe [String] |
107 | loaderFFIOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.ffi) (read query) | ||
diff --git a/src/Path.purs b/src/Path.purs deleted file mode 100644 index e071e35..0000000 --- a/src/Path.purs +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | module PursLoader.Path | ||
2 | ( dirname | ||
3 | , join | ||
4 | , relative | ||
5 | , resolve | ||
6 | ) where | ||
7 | |||
8 | foreign import dirname """ | ||
9 | function dirname(filepath) { | ||
10 | var path = require('path'); | ||
11 | return path.dirname(filepath); | ||
12 | } | ||
13 | """ :: String -> String | ||
14 | |||
15 | foreign import join """ | ||
16 | function join(parts) { | ||
17 | var path = require('path'); | ||
18 | return path.join.apply(path, parts); | ||
19 | } | ||
20 | """ :: [String] -> String | ||
21 | |||
22 | foreign import relative """ | ||
23 | function relative(from) { | ||
24 | return function(to){ | ||
25 | var path = require('path'); | ||
26 | return path.relative(from, to); | ||
27 | }; | ||
28 | } | ||
29 | """ :: String -> String -> String | ||
30 | |||
31 | foreign import resolve """ | ||
32 | function resolve(filepath) { | ||
33 | var path = require('path'); | ||
34 | return path.resolve(filepath); | ||
35 | } | ||
36 | """ :: String -> String | ||