diff options
Diffstat (limited to 'src/PursLoader')
-rw-r--r-- | src/PursLoader/ChildProcess.js | 40 | ||||
-rw-r--r-- | src/PursLoader/ChildProcess.purs | 49 | ||||
-rw-r--r-- | src/PursLoader/FS.js | 36 | ||||
-rw-r--r-- | src/PursLoader/FS.purs | 59 | ||||
-rw-r--r-- | src/PursLoader/Glob.js | 18 | ||||
-rw-r--r-- | src/PursLoader/Glob.purs | 25 | ||||
-rw-r--r-- | src/PursLoader/Loader.js | 17 | ||||
-rw-r--r-- | src/PursLoader/Loader.purs | 19 | ||||
-rw-r--r-- | src/PursLoader/LoaderRef.js | 56 | ||||
-rw-r--r-- | src/PursLoader/LoaderRef.purs | 56 | ||||
-rw-r--r-- | src/PursLoader/LoaderUtil.js | 7 | ||||
-rw-r--r-- | src/PursLoader/LoaderUtil.purs | 6 | ||||
-rw-r--r-- | src/PursLoader/Options.purs | 16 |
13 files changed, 232 insertions, 172 deletions
diff --git a/src/PursLoader/ChildProcess.js b/src/PursLoader/ChildProcess.js new file mode 100644 index 0000000..d62aef6 --- /dev/null +++ b/src/PursLoader/ChildProcess.js | |||
@@ -0,0 +1,40 @@ | |||
1 | 'use strict'; | ||
2 | |||
3 | // module PursLoader.ChildProcess | ||
4 | |||
5 | var child_process = require('child_process'); | ||
6 | |||
7 | var chalk = require('chalk'); | ||
8 | |||
9 | function spawnFn(command, args, errback, callback) { | ||
10 | return function(){ | ||
11 | var process = child_process.spawn(command, args); | ||
12 | |||
13 | var stdout = new Buffer(0); | ||
14 | |||
15 | var stderr = new Buffer(0); | ||
16 | |||
17 | process.stdout.on('data', function(data){ | ||
18 | stdout = Buffer.concat([stdout, new Buffer(data)]); | ||
19 | }); | ||
20 | |||
21 | process.stderr.on('data', function(data){ | ||
22 | stderr = Buffer.concat([stderr, new Buffer(data)]); | ||
23 | }); | ||
24 | |||
25 | process.on('close', function(code){ | ||
26 | var output = stdout.toString('utf-8'); | ||
27 | |||
28 | var error = stderr.toString('utf-8'); | ||
29 | |||
30 | if (error.length > 0) { | ||
31 | console.error('\n' + chalk.red('*') + ' ' + error); | ||
32 | } | ||
33 | |||
34 | if (code !== 0) errback(new Error('Process terminated with code ' + code))(); | ||
35 | else callback(output)(); | ||
36 | }); | ||
37 | }; | ||
38 | } | ||
39 | |||
40 | exports.spawnFn = spawnFn; | ||
diff --git a/src/PursLoader/ChildProcess.purs b/src/PursLoader/ChildProcess.purs index 34558fa..3bd960b 100644 --- a/src/PursLoader/ChildProcess.purs +++ b/src/PursLoader/ChildProcess.purs | |||
@@ -3,6 +3,8 @@ module PursLoader.ChildProcess | |||
3 | , spawn | 3 | , spawn |
4 | ) where | 4 | ) where |
5 | 5 | ||
6 | import Prelude (Unit(), ($)) | ||
7 | |||
6 | import Control.Monad.Aff (Aff(), makeAff) | 8 | import Control.Monad.Aff (Aff(), makeAff) |
7 | import Control.Monad.Eff (Eff()) | 9 | import Control.Monad.Eff (Eff()) |
8 | import Control.Monad.Eff.Exception (Error()) | 10 | import Control.Monad.Eff.Exception (Error()) |
@@ -11,46 +13,11 @@ import Data.Function | |||
11 | 13 | ||
12 | foreign import data ChildProcess :: ! | 14 | foreign import data ChildProcess :: ! |
13 | 15 | ||
14 | spawn :: forall eff. String -> [String] -> Aff (cp :: ChildProcess | eff) String | 16 | spawn :: forall eff. String -> Array String -> Aff (cp :: ChildProcess | eff) String |
15 | spawn command args = makeAff $ runFn4 spawnFn command args | 17 | spawn command args = makeAff $ runFn4 spawnFn command args |
16 | 18 | ||
17 | foreign import spawnFn """ | 19 | foreign import spawnFn :: forall eff. Fn4 String |
18 | function spawnFn(command, args, errback, callback) { | 20 | (Array String) |
19 | return function(){ | 21 | (Error -> Eff (cp :: ChildProcess | eff) Unit) |
20 | var child_process = require('child_process'); | 22 | (String -> Eff (cp :: ChildProcess | eff) Unit) |
21 | 23 | (Eff (cp :: ChildProcess | eff) Unit) | |
22 | var process = child_process.spawn(command, args); | ||
23 | |||
24 | var stdout = new Buffer(0); | ||
25 | |||
26 | var stderr = new Buffer(0); | ||
27 | |||
28 | process.stdout.on('data', function(data){ | ||
29 | stdout = Buffer.concat([stdout, new Buffer(data)]); | ||
30 | }); | ||
31 | |||
32 | process.stderr.on('data', function(data){ | ||
33 | stderr = Buffer.concat([stderr, new Buffer(data)]); | ||
34 | }); | ||
35 | |||
36 | process.on('close', function(code){ | ||
37 | var chalk = require('chalk'); | ||
38 | |||
39 | var output = stdout.toString('utf-8'); | ||
40 | |||
41 | var error = stderr.toString('utf-8'); | ||
42 | |||
43 | if (error.length > 0) { | ||
44 | console.error('\n' + chalk.red('*') + ' ' + error); | ||
45 | } | ||
46 | |||
47 | if (code !== 0) errback(new Error('Process terminated with code ' + code))(); | ||
48 | else callback(output)(); | ||
49 | }); | ||
50 | }; | ||
51 | } | ||
52 | """ :: forall eff. Fn4 String | ||
53 | [String] | ||
54 | (Error -> Eff (cp :: ChildProcess | eff) Unit) | ||
55 | (String -> Eff (cp :: ChildProcess | eff) Unit) | ||
56 | (Eff (cp :: ChildProcess | eff) Unit) | ||
diff --git a/src/PursLoader/FS.js b/src/PursLoader/FS.js new file mode 100644 index 0000000..1a7f5b0 --- /dev/null +++ b/src/PursLoader/FS.js | |||
@@ -0,0 +1,36 @@ | |||
1 | 'use strict'; | ||
2 | |||
3 | // module PursLoader.FS | ||
4 | |||
5 | var fs = require('fs'); | ||
6 | |||
7 | var async = require('async'); | ||
8 | |||
9 | function writeFileUtf8Fn(filepath, contents, errback, callback) { | ||
10 | return function(){ | ||
11 | fs.writeFile(filepath, contents, function(error){ | ||
12 | if (error) errback(error)(); | ||
13 | else callback()(); | ||
14 | }); | ||
15 | }; | ||
16 | } | ||
17 | |||
18 | function findFileUtf8Fn(nothing, just, regex, filepaths, errback, callback) { | ||
19 | return function(){ | ||
20 | function findFile(filepath, callback) { | ||
21 | fs.readFile(filepath, {encoding: 'utf-8'}, function(error, result){ | ||
22 | if (error) callback(false); | ||
23 | else callback(regex.test(result)); | ||
24 | }); | ||
25 | } | ||
26 | |||
27 | async.detect(filepaths, findFile, function(result){ | ||
28 | if (!result) callback(nothing)(); | ||
29 | else callback(just(result))(); | ||
30 | }); | ||
31 | }; | ||
32 | } | ||
33 | |||
34 | exports.writeFileUtf8Fn = writeFileUtf8Fn; | ||
35 | |||
36 | exports.findFileUtf8Fn = findFileUtf8Fn; | ||
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) | ||
diff --git a/src/PursLoader/Glob.js b/src/PursLoader/Glob.js new file mode 100644 index 0000000..960ae9a --- /dev/null +++ b/src/PursLoader/Glob.js | |||
@@ -0,0 +1,18 @@ | |||
1 | 'use strict'; | ||
2 | |||
3 | // module PursLoader.Glob | ||
4 | |||
5 | var glob = require('glob'); | ||
6 | |||
7 | var async = require('async'); | ||
8 | |||
9 | function globAllFn(patterns, errback, callback) { | ||
10 | return function(){ | ||
11 | async.map(patterns, glob, function(error, result){ | ||
12 | if (error) errback(new Error(error))(); | ||
13 | else callback(result)(); | ||
14 | }); | ||
15 | }; | ||
16 | } | ||
17 | |||
18 | exports.globAllFn = globAllFn; | ||
diff --git a/src/PursLoader/Glob.purs b/src/PursLoader/Glob.purs index 392d9e4..45eeb56 100644 --- a/src/PursLoader/Glob.purs +++ b/src/PursLoader/Glob.purs | |||
@@ -3,6 +3,8 @@ module PursLoader.Glob | |||
3 | , globAll | 3 | , globAll |
4 | ) where | 4 | ) where |
5 | 5 | ||
6 | import Prelude (Unit(), ($)) | ||
7 | |||
6 | import Control.Monad.Aff (Aff(), makeAff) | 8 | import Control.Monad.Aff (Aff(), makeAff) |
7 | import Control.Monad.Eff (Eff()) | 9 | import Control.Monad.Eff (Eff()) |
8 | import Control.Monad.Eff.Exception (Error()) | 10 | import Control.Monad.Eff.Exception (Error()) |
@@ -11,23 +13,10 @@ import Data.Function | |||
11 | 13 | ||
12 | foreign import data Glob :: ! | 14 | foreign import data Glob :: ! |
13 | 15 | ||
14 | globAll :: forall eff. [String] -> Aff (glob :: Glob | eff) [[String]] | 16 | globAll :: forall eff. Array String -> Aff (glob :: Glob | eff) (Array (Array String)) |
15 | globAll patterns = makeAff $ runFn3 globAllFn patterns | 17 | globAll patterns = makeAff $ runFn3 globAllFn patterns |
16 | 18 | ||
17 | foreign import globAllFn """ | 19 | foreign import globAllFn :: forall eff. Fn3 (Array String) |
18 | function globAllFn(patterns, errback, callback) { | 20 | (Error -> Eff (glob :: Glob | eff) Unit) |
19 | return function(){ | 21 | ((Array (Array String)) -> Eff (glob :: Glob | eff) Unit) |
20 | var glob = require('glob'); | 22 | (Eff (glob :: Glob | eff) Unit) |
21 | |||
22 | var async = require('async'); | ||
23 | |||
24 | async.map(patterns, glob, function(error, result){ | ||
25 | if (error) errback(new Error(error))(); | ||
26 | else callback(result)(); | ||
27 | }); | ||
28 | }; | ||
29 | } | ||
30 | """ :: forall eff. Fn3 [String] | ||
31 | (Error -> Eff (glob :: Glob | eff) Unit) | ||
32 | ([[String]] -> Eff (glob :: Glob | eff) Unit) | ||
33 | (Eff (glob :: Glob | eff) Unit) | ||
diff --git a/src/PursLoader/Loader.js b/src/PursLoader/Loader.js new file mode 100644 index 0000000..d7b5578 --- /dev/null +++ b/src/PursLoader/Loader.js | |||
@@ -0,0 +1,17 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | // module PursLoader.Loader | ||
4 | |||
5 | var path = require('path'); | ||
6 | |||
7 | var cwd = process.cwd(); | ||
8 | |||
9 | function relative(from) { | ||
10 | return function(to){ | ||
11 | return path.relative(from, to); | ||
12 | }; | ||
13 | } | ||
14 | |||
15 | exports.cwd = cwd; | ||
16 | |||
17 | exports.relative = relative; | ||
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 | ||
diff --git a/src/PursLoader/LoaderRef.js b/src/PursLoader/LoaderRef.js new file mode 100644 index 0000000..3ce0970 --- /dev/null +++ b/src/PursLoader/LoaderRef.js | |||
@@ -0,0 +1,56 @@ | |||
1 | 'use strict'; | ||
2 | |||
3 | // module PursLoader.LoaderRef | ||
4 | |||
5 | function asyncFn(isJust, fromMaybe, ref){ | ||
6 | return function(){ | ||
7 | var callback = ref.async(); | ||
8 | return function(error){ | ||
9 | return function(value){ | ||
10 | return function(){ | ||
11 | return isJust(error) ? callback(fromMaybe(new Error())(error)) | ||
12 | : callback(null, value); | ||
13 | }; | ||
14 | }; | ||
15 | }; | ||
16 | }; | ||
17 | } | ||
18 | function cacheable(ref){ | ||
19 | return function(){ | ||
20 | return ref.cacheable && ref.cacheable(); | ||
21 | }; | ||
22 | } | ||
23 | |||
24 | function query(ref){ | ||
25 | return ref.query; | ||
26 | } | ||
27 | |||
28 | function clearDependencies(ref){ | ||
29 | return function(){ | ||
30 | return ref.clearDependencies(); | ||
31 | }; | ||
32 | } | ||
33 | |||
34 | function resourcePath(ref){ | ||
35 | return ref.resourcePath; | ||
36 | } | ||
37 | |||
38 | function addDependency(ref){ | ||
39 | return function(dep){ | ||
40 | return function(){ | ||
41 | return ref.addDependency(dep); | ||
42 | }; | ||
43 | }; | ||
44 | } | ||
45 | |||
46 | exports.asyncFn = asyncFn; | ||
47 | |||
48 | exports.cacheable = cacheable; | ||
49 | |||
50 | exports.query = query; | ||
51 | |||
52 | exports.clearDependencies = clearDependencies; | ||
53 | |||
54 | exports.resourcePath = resourcePath; | ||
55 | |||
56 | exports.addDependency = addDependency; | ||
diff --git a/src/PursLoader/LoaderRef.purs b/src/PursLoader/LoaderRef.purs index f1efa04..33c4f7e 100644 --- a/src/PursLoader/LoaderRef.purs +++ b/src/PursLoader/LoaderRef.purs | |||
@@ -9,6 +9,8 @@ module PursLoader.LoaderRef | |||
9 | , resourcePath | 9 | , resourcePath |
10 | ) where | 10 | ) where |
11 | 11 | ||
12 | import Prelude (Unit()) | ||
13 | |||
12 | import Control.Monad.Eff (Eff()) | 14 | import Control.Monad.Eff (Eff()) |
13 | import Control.Monad.Eff.Exception (Error()) | 15 | import Control.Monad.Eff.Exception (Error()) |
14 | 16 | ||
@@ -19,56 +21,20 @@ data LoaderRef | |||
19 | 21 | ||
20 | foreign import data Loader :: ! | 22 | foreign import data Loader :: ! |
21 | 23 | ||
22 | foreign import asyncFn """ | 24 | foreign import asyncFn :: forall eff a. Fn3 (Maybe Error -> Boolean) |
23 | function asyncFn(isJust, fromMaybe, ref){ | 25 | (Error -> Maybe Error -> Error) |
24 | return function(){ | 26 | LoaderRef |
25 | var callback = ref.async(); | 27 | (Eff (loader :: Loader | eff) (Maybe Error -> a -> Eff (loader :: Loader | eff) Unit)) |
26 | return function(error){ | ||
27 | return function(value){ | ||
28 | return function(){ | ||
29 | return isJust(error) ? callback(fromMaybe(new Error())(error)) | ||
30 | : callback(null, value); | ||
31 | }; | ||
32 | }; | ||
33 | }; | ||
34 | }; | ||
35 | }""" :: forall eff a. Fn3 (Maybe Error -> Boolean) | ||
36 | (Error -> Maybe Error -> Error) | ||
37 | LoaderRef | ||
38 | (Eff (loader :: Loader | eff) (Maybe Error -> a -> Eff (loader :: Loader | eff) Unit)) | ||
39 | 28 | ||
40 | async :: forall eff a. LoaderRef -> Eff (loader :: Loader | eff) (Maybe Error -> a -> Eff (loader :: Loader | eff) Unit) | 29 | async :: forall eff a. LoaderRef -> Eff (loader :: Loader | eff) (Maybe Error -> a -> Eff (loader :: Loader | eff) Unit) |
41 | async ref = runFn3 asyncFn isJust fromMaybe ref | 30 | async ref = runFn3 asyncFn isJust fromMaybe ref |
42 | 31 | ||
43 | foreign import cacheable """ | 32 | foreign import cacheable :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit |
44 | function cacheable(ref){ | ||
45 | return function(){ | ||
46 | return ref.cacheable && ref.cacheable(); | ||
47 | }; | ||
48 | }""" :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit | ||
49 | 33 | ||
50 | foreign import query """ | 34 | foreign import query :: LoaderRef -> String |
51 | function query(ref){ | ||
52 | return ref.query; | ||
53 | }""" :: LoaderRef -> String | ||
54 | 35 | ||
55 | foreign import clearDependencies """ | 36 | foreign import clearDependencies :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit |
56 | function clearDependencies(ref){ | ||
57 | return function(){ | ||
58 | return ref.clearDependencies(); | ||
59 | }; | ||
60 | }""" :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit | ||
61 | 37 | ||
62 | foreign import resourcePath """ | 38 | foreign import resourcePath :: LoaderRef -> String |
63 | function resourcePath(ref){ | ||
64 | return ref.resourcePath; | ||
65 | }""" :: LoaderRef -> String | ||
66 | 39 | ||
67 | foreign import addDependency """ | 40 | foreign import addDependency :: forall eff. LoaderRef -> String -> Eff (loader :: Loader | eff) Unit |
68 | function addDependency(ref){ | ||
69 | return function(dep){ | ||
70 | return function(){ | ||
71 | return ref.addDependency(dep); | ||
72 | }; | ||
73 | }; | ||
74 | }""" :: forall eff. LoaderRef -> String -> Eff (loader :: Loader | eff) Unit | ||
diff --git a/src/PursLoader/LoaderUtil.js b/src/PursLoader/LoaderUtil.js new file mode 100644 index 0000000..45f2703 --- /dev/null +++ b/src/PursLoader/LoaderUtil.js | |||
@@ -0,0 +1,7 @@ | |||
1 | 'use strict'; | ||
2 | |||
3 | // module PursLoader.LoaderUtil | ||
4 | |||
5 | var loaderUtils = require('loader-utils'); | ||
6 | |||
7 | exports.parseQuery = loaderUtils.parseQuery; | ||
diff --git a/src/PursLoader/LoaderUtil.purs b/src/PursLoader/LoaderUtil.purs index 86be124..3e5a7bc 100644 --- a/src/PursLoader/LoaderUtil.purs +++ b/src/PursLoader/LoaderUtil.purs | |||
@@ -6,8 +6,4 @@ import Data.Foreign (Foreign()) | |||
6 | 6 | ||
7 | import PursLoader.LoaderRef (LoaderRef()) | 7 | import PursLoader.LoaderRef (LoaderRef()) |
8 | 8 | ||
9 | foreign import parseQuery """ | 9 | foreign import parseQuery :: String -> Foreign |
10 | function parseQuery(query){ | ||
11 | var loaderUtils = require('loader-utils'); | ||
12 | return loaderUtils.parseQuery(query); | ||
13 | }""" :: String -> Foreign | ||
diff --git a/src/PursLoader/Options.purs b/src/PursLoader/Options.purs index 51e9be5..e3957eb 100644 --- a/src/PursLoader/Options.purs +++ b/src/PursLoader/Options.purs | |||
@@ -4,6 +4,8 @@ module PursLoader.Options | |||
4 | , loaderFFIOption | 4 | , loaderFFIOption |
5 | ) where | 5 | ) where |
6 | 6 | ||
7 | import Prelude (Unit(), (<>), (<$>), (<<<), (++), (<*>), const) | ||
8 | |||
7 | import Data.Array (concat) | 9 | import Data.Array (concat) |
8 | import Data.Either (either) | 10 | import Data.Either (either) |
9 | 11 | ||
@@ -45,8 +47,8 @@ newtype Options | |||
45 | , output :: NullOrUndefined String | 47 | , output :: NullOrUndefined String |
46 | , noPrefix :: NullOrUndefined Boolean | 48 | , noPrefix :: NullOrUndefined Boolean |
47 | , requirePath :: NullOrUndefined String | 49 | , requirePath :: NullOrUndefined String |
48 | , src :: NullOrUndefined [String] | 50 | , src :: NullOrUndefined (Array String) |
49 | , ffi :: NullOrUndefined [String] | 51 | , ffi :: NullOrUndefined (Array String) |
50 | } | 52 | } |
51 | 53 | ||
52 | instance isForeignOptions :: IsForeign Options where | 54 | instance isForeignOptions :: IsForeign Options where |
@@ -74,7 +76,7 @@ instance isForeignOptions :: IsForeign Options where | |||
74 | <*> readProp ffiOpt obj) | 76 | <*> readProp ffiOpt obj) |
75 | 77 | ||
76 | class LoaderOption a where | 78 | class LoaderOption a where |
77 | opt :: String -> NullOrUndefined a -> [String] | 79 | opt :: String -> NullOrUndefined a -> Array String |
78 | 80 | ||
79 | instance booleanLoaderOption :: LoaderOption Boolean where | 81 | instance booleanLoaderOption :: LoaderOption Boolean where |
80 | opt key val = maybe [] (\a -> if a then ["--" ++ key] else []) (runNullOrUndefined val) | 82 | opt key val = maybe [] (\a -> if a then ["--" ++ key] else []) (runNullOrUndefined val) |
@@ -82,11 +84,11 @@ instance booleanLoaderOption :: LoaderOption Boolean where | |||
82 | instance stringLoaderOption :: LoaderOption String where | 84 | instance stringLoaderOption :: LoaderOption String where |
83 | opt key val = maybe [] (\a -> ["--" ++ key ++ "=" ++ a]) (runNullOrUndefined val) | 85 | opt key val = maybe [] (\a -> ["--" ++ key ++ "=" ++ a]) (runNullOrUndefined val) |
84 | 86 | ||
85 | instance arrayLoaderOption :: (LoaderOption a) => LoaderOption [a] where | 87 | instance arrayLoaderOption :: (LoaderOption a) => LoaderOption (Array a) where |
86 | opt key val = concat (opt key <$> (NullOrUndefined <<< Just) | 88 | opt key val = concat (opt key <$> (NullOrUndefined <<< Just) |
87 | <$> (fromMaybe [] (runNullOrUndefined val))) | 89 | <$> (fromMaybe [] (runNullOrUndefined val))) |
88 | 90 | ||
89 | pscOptions :: Foreign -> [String] | 91 | pscOptions :: Foreign -> Array String |
90 | pscOptions query = either (const []) fold parsed | 92 | pscOptions query = either (const []) fold parsed |
91 | where parsed = read query :: F Options | 93 | where parsed = read query :: F Options |
92 | fold (Options a) = opt noPreludeOpt a.noPrelude <> | 94 | fold (Options a) = opt noPreludeOpt a.noPrelude <> |
@@ -100,8 +102,8 @@ pscOptions query = either (const []) fold parsed | |||
100 | opt requirePathOpt a.requirePath <> | 102 | opt requirePathOpt a.requirePath <> |
101 | opt ffiOpt a.ffi | 103 | opt ffiOpt a.ffi |
102 | 104 | ||
103 | loaderSrcOption :: Foreign -> Maybe [String] | 105 | loaderSrcOption :: Foreign -> Maybe (Array String) |
104 | loaderSrcOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.src) (read query) | 106 | loaderSrcOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.src) (read query) |
105 | 107 | ||
106 | loaderFFIOption :: Foreign -> Maybe [String] | 108 | loaderFFIOption :: Foreign -> Maybe (Array String) |
107 | loaderFFIOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.ffi) (read query) | 109 | loaderFFIOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.ffi) (read query) |