diff options
author | eric <thul.eric@gmail.com> | 2015-08-11 21:23:46 -0400 |
---|---|---|
committer | eric <thul.eric@gmail.com> | 2015-08-11 21:23:46 -0400 |
commit | 7226ff961c104037e8e5d3705949e2e9d58a6727 (patch) | |
tree | 555547366ccadfe71689b95a6b16b855b6173364 | |
parent | eae2e182cec2d521166e5775294b52300c42f069 (diff) | |
parent | 07de44be15efb0ca9a2d1443ab1e91076a25409c (diff) | |
download | purs-loader-7226ff961c104037e8e5d3705949e2e9d58a6727.tar.gz purs-loader-7226ff961c104037e8e5d3705949e2e9d58a6727.tar.zst purs-loader-7226ff961c104037e8e5d3705949e2e9d58a6727.zip |
Merge pull request #27 from ethul/topic/issue-26
Topic/issue 26
28 files changed, 456 insertions, 428 deletions
diff --git a/MODULE.md b/MODULE.md deleted file mode 100644 index 45f6cca..0000000 --- a/MODULE.md +++ /dev/null | |||
@@ -1,178 +0,0 @@ | |||
1 | # Module Documentation | ||
2 | |||
3 | ## Module PursLoader.ChildProcess | ||
4 | |||
5 | #### `ChildProcess` | ||
6 | |||
7 | ``` purescript | ||
8 | data ChildProcess :: ! | ||
9 | ``` | ||
10 | |||
11 | |||
12 | #### `spawn` | ||
13 | |||
14 | ``` purescript | ||
15 | spawn :: forall eff. String -> [String] -> Aff (cp :: ChildProcess | eff) String | ||
16 | ``` | ||
17 | |||
18 | |||
19 | |||
20 | ## Module PursLoader.FS | ||
21 | |||
22 | #### `FS` | ||
23 | |||
24 | ``` purescript | ||
25 | data FS :: ! | ||
26 | ``` | ||
27 | |||
28 | |||
29 | #### `writeFileUtf8` | ||
30 | |||
31 | ``` purescript | ||
32 | writeFileUtf8 :: forall eff. String -> String -> Aff (fs :: FS | eff) Unit | ||
33 | ``` | ||
34 | |||
35 | |||
36 | |||
37 | ## Module PursLoader.Glob | ||
38 | |||
39 | #### `Glob` | ||
40 | |||
41 | ``` purescript | ||
42 | data Glob :: ! | ||
43 | ``` | ||
44 | |||
45 | |||
46 | #### `globAll` | ||
47 | |||
48 | ``` purescript | ||
49 | globAll :: forall eff. [String] -> Aff (glob :: Glob | eff) [[String]] | ||
50 | ``` | ||
51 | |||
52 | |||
53 | |||
54 | ## Module PursLoader.Loader | ||
55 | |||
56 | #### `Effects` | ||
57 | |||
58 | ``` purescript | ||
59 | type Effects eff = (loader :: Loader, glob :: Glob, fs :: FS, cp :: ChildProcess | eff) | ||
60 | ``` | ||
61 | |||
62 | |||
63 | #### `loader` | ||
64 | |||
65 | ``` purescript | ||
66 | loader :: forall eff. LoaderRef -> String -> Eff (Effects eff) Unit | ||
67 | ``` | ||
68 | |||
69 | |||
70 | #### `loaderFn` | ||
71 | |||
72 | ``` purescript | ||
73 | loaderFn :: forall eff. Fn2 LoaderRef String (Eff (Effects eff) Unit) | ||
74 | ``` | ||
75 | |||
76 | |||
77 | |||
78 | ## Module PursLoader.LoaderRef | ||
79 | |||
80 | #### `LoaderRef` | ||
81 | |||
82 | ``` purescript | ||
83 | data LoaderRef | ||
84 | ``` | ||
85 | |||
86 | |||
87 | #### `Loader` | ||
88 | |||
89 | ``` purescript | ||
90 | data Loader :: ! | ||
91 | ``` | ||
92 | |||
93 | |||
94 | #### `async` | ||
95 | |||
96 | ``` purescript | ||
97 | async :: forall eff a. LoaderRef -> Eff (loader :: Loader | eff) (Maybe Error -> a -> Eff (loader :: Loader | eff) Unit) | ||
98 | ``` | ||
99 | |||
100 | |||
101 | #### `cacheable` | ||
102 | |||
103 | ``` purescript | ||
104 | cacheable :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit | ||
105 | ``` | ||
106 | |||
107 | |||
108 | #### `query` | ||
109 | |||
110 | ``` purescript | ||
111 | query :: LoaderRef -> String | ||
112 | ``` | ||
113 | |||
114 | |||
115 | |||
116 | ## Module PursLoader.LoaderUtil | ||
117 | |||
118 | #### `parseQuery` | ||
119 | |||
120 | ``` purescript | ||
121 | parseQuery :: String -> Foreign | ||
122 | ``` | ||
123 | |||
124 | |||
125 | |||
126 | ## Module PursLoader.Options | ||
127 | |||
128 | #### `isForeignOptions` | ||
129 | |||
130 | ``` purescript | ||
131 | instance isForeignOptions :: IsForeign Options | ||
132 | ``` | ||
133 | |||
134 | |||
135 | #### `booleanLoaderOption` | ||
136 | |||
137 | ``` purescript | ||
138 | instance booleanLoaderOption :: LoaderOption Boolean | ||
139 | ``` | ||
140 | |||
141 | |||
142 | #### `stringLoaderOption` | ||
143 | |||
144 | ``` purescript | ||
145 | instance stringLoaderOption :: LoaderOption String | ||
146 | ``` | ||
147 | |||
148 | |||
149 | #### `arrayLoaderOption` | ||
150 | |||
151 | ``` purescript | ||
152 | instance arrayLoaderOption :: (LoaderOption a) => LoaderOption [a] | ||
153 | ``` | ||
154 | |||
155 | |||
156 | #### `pscOptions` | ||
157 | |||
158 | ``` purescript | ||
159 | pscOptions :: Foreign -> [String] | ||
160 | ``` | ||
161 | |||
162 | |||
163 | #### `loaderSrcOption` | ||
164 | |||
165 | ``` purescript | ||
166 | loaderSrcOption :: Foreign -> Maybe [String] | ||
167 | ``` | ||
168 | |||
169 | |||
170 | #### `loaderFFIOption` | ||
171 | |||
172 | ``` purescript | ||
173 | loaderFFIOption :: Foreign -> Maybe [String] | ||
174 | ``` | ||
175 | |||
176 | |||
177 | |||
178 | |||
@@ -2,16 +2,8 @@ | |||
2 | "name": "purs-loader", | 2 | "name": "purs-loader", |
3 | "private": true, | 3 | "private": true, |
4 | "devDependencies": { | 4 | "devDependencies": { |
5 | "purescript-aff": "~0.9.1", | 5 | "purescript-aff": "~0.11.3", |
6 | "purescript-exceptions": "~0.2.3", | 6 | "purescript-strings": "~0.6.0", |
7 | "purescript-strings": "~0.4.5", | 7 | "purescript-foreign": "~0.6.0" |
8 | "purescript-maybe": "~0.2.2", | ||
9 | "purescript-foreign": "~0.4.2", | ||
10 | "purescript-foldable-traversable": "~0.3.1", | ||
11 | "purescript-tuples": "~0.3.4", | ||
12 | "purescript-maps": "~0.3.3", | ||
13 | "purescript-arrays": "~0.3.7", | ||
14 | "purescript-monad-eff": "~0.1.0", | ||
15 | "purescript-sets": "0.3.2" | ||
16 | } | 8 | } |
17 | } | 9 | } |
diff --git a/docs/PursLoader/ChildProcess.md b/docs/PursLoader/ChildProcess.md new file mode 100644 index 0000000..7c2e414 --- /dev/null +++ b/docs/PursLoader/ChildProcess.md | |||
@@ -0,0 +1,15 @@ | |||
1 | ## Module PursLoader.ChildProcess | ||
2 | |||
3 | #### `ChildProcess` | ||
4 | |||
5 | ``` purescript | ||
6 | data ChildProcess :: ! | ||
7 | ``` | ||
8 | |||
9 | #### `spawn` | ||
10 | |||
11 | ``` purescript | ||
12 | spawn :: forall eff. String -> Array String -> Aff (cp :: ChildProcess | eff) String | ||
13 | ``` | ||
14 | |||
15 | |||
diff --git a/docs/PursLoader/FS.md b/docs/PursLoader/FS.md new file mode 100644 index 0000000..811fcbd --- /dev/null +++ b/docs/PursLoader/FS.md | |||
@@ -0,0 +1,21 @@ | |||
1 | ## Module PursLoader.FS | ||
2 | |||
3 | #### `FS` | ||
4 | |||
5 | ``` purescript | ||
6 | data FS :: ! | ||
7 | ``` | ||
8 | |||
9 | #### `writeFileUtf8` | ||
10 | |||
11 | ``` purescript | ||
12 | writeFileUtf8 :: forall eff. String -> String -> Aff (fs :: FS | eff) Unit | ||
13 | ``` | ||
14 | |||
15 | #### `findFileUtf8` | ||
16 | |||
17 | ``` purescript | ||
18 | findFileUtf8 :: forall eff. Regex -> Array String -> Aff (fs :: FS | eff) (Maybe String) | ||
19 | ``` | ||
20 | |||
21 | |||
diff --git a/docs/PursLoader/Glob.md b/docs/PursLoader/Glob.md new file mode 100644 index 0000000..f7abe78 --- /dev/null +++ b/docs/PursLoader/Glob.md | |||
@@ -0,0 +1,15 @@ | |||
1 | ## Module PursLoader.Glob | ||
2 | |||
3 | #### `Glob` | ||
4 | |||
5 | ``` purescript | ||
6 | data Glob :: ! | ||
7 | ``` | ||
8 | |||
9 | #### `globAll` | ||
10 | |||
11 | ``` purescript | ||
12 | globAll :: forall eff. Array String -> Aff (glob :: Glob | eff) (Array (Array String)) | ||
13 | ``` | ||
14 | |||
15 | |||
diff --git a/docs/PursLoader/Loader.md b/docs/PursLoader/Loader.md new file mode 100644 index 0000000..8e91c4a --- /dev/null +++ b/docs/PursLoader/Loader.md | |||
@@ -0,0 +1,21 @@ | |||
1 | ## Module PursLoader.Loader | ||
2 | |||
3 | #### `Effects` | ||
4 | |||
5 | ``` purescript | ||
6 | type Effects eff = (cp :: ChildProcess, fs :: FS, glob :: Glob, loader :: Loader | eff) | ||
7 | ``` | ||
8 | |||
9 | #### `loader` | ||
10 | |||
11 | ``` purescript | ||
12 | loader :: forall eff. LoaderRef -> String -> Eff (Effects eff) Unit | ||
13 | ``` | ||
14 | |||
15 | #### `loaderFn` | ||
16 | |||
17 | ``` purescript | ||
18 | loaderFn :: forall eff. Fn2 LoaderRef String (Eff (Effects eff) Unit) | ||
19 | ``` | ||
20 | |||
21 | |||
diff --git a/docs/PursLoader/LoaderRef.md b/docs/PursLoader/LoaderRef.md new file mode 100644 index 0000000..36c1550 --- /dev/null +++ b/docs/PursLoader/LoaderRef.md | |||
@@ -0,0 +1,51 @@ | |||
1 | ## Module PursLoader.LoaderRef | ||
2 | |||
3 | #### `LoaderRef` | ||
4 | |||
5 | ``` purescript | ||
6 | data LoaderRef | ||
7 | ``` | ||
8 | |||
9 | #### `Loader` | ||
10 | |||
11 | ``` purescript | ||
12 | data Loader :: ! | ||
13 | ``` | ||
14 | |||
15 | #### `async` | ||
16 | |||
17 | ``` purescript | ||
18 | async :: forall eff a. LoaderRef -> Eff (loader :: Loader | eff) (Maybe Error -> a -> Eff (loader :: Loader | eff) Unit) | ||
19 | ``` | ||
20 | |||
21 | #### `cacheable` | ||
22 | |||
23 | ``` purescript | ||
24 | cacheable :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit | ||
25 | ``` | ||
26 | |||
27 | #### `query` | ||
28 | |||
29 | ``` purescript | ||
30 | query :: LoaderRef -> String | ||
31 | ``` | ||
32 | |||
33 | #### `clearDependencies` | ||
34 | |||
35 | ``` purescript | ||
36 | clearDependencies :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit | ||
37 | ``` | ||
38 | |||
39 | #### `resourcePath` | ||
40 | |||
41 | ``` purescript | ||
42 | resourcePath :: LoaderRef -> String | ||
43 | ``` | ||
44 | |||
45 | #### `addDependency` | ||
46 | |||
47 | ``` purescript | ||
48 | addDependency :: forall eff. LoaderRef -> String -> Eff (loader :: Loader | eff) Unit | ||
49 | ``` | ||
50 | |||
51 | |||
diff --git a/docs/PursLoader/LoaderUtil.md b/docs/PursLoader/LoaderUtil.md new file mode 100644 index 0000000..36d6879 --- /dev/null +++ b/docs/PursLoader/LoaderUtil.md | |||
@@ -0,0 +1,9 @@ | |||
1 | ## Module PursLoader.LoaderUtil | ||
2 | |||
3 | #### `parseQuery` | ||
4 | |||
5 | ``` purescript | ||
6 | parseQuery :: String -> Foreign | ||
7 | ``` | ||
8 | |||
9 | |||
diff --git a/docs/PursLoader/Options.md b/docs/PursLoader/Options.md new file mode 100644 index 0000000..d04b721 --- /dev/null +++ b/docs/PursLoader/Options.md | |||
@@ -0,0 +1,21 @@ | |||
1 | ## Module PursLoader.Options | ||
2 | |||
3 | #### `pscOptions` | ||
4 | |||
5 | ``` purescript | ||
6 | pscOptions :: Foreign -> Array String | ||
7 | ``` | ||
8 | |||
9 | #### `loaderSrcOption` | ||
10 | |||
11 | ``` purescript | ||
12 | loaderSrcOption :: Foreign -> Maybe (Array String) | ||
13 | ``` | ||
14 | |||
15 | #### `loaderFFIOption` | ||
16 | |||
17 | ``` purescript | ||
18 | loaderFFIOption :: Foreign -> Maybe (Array String) | ||
19 | ``` | ||
20 | |||
21 | |||
diff --git a/example/src/entry.js b/example/src/entry.js index a41536c..cde8507 100644 --- a/example/src/entry.js +++ b/example/src/entry.js | |||
@@ -6,6 +6,4 @@ var foo = require('./Foo.purs'); | |||
6 | 6 | ||
7 | var baz = require('./Foo/Baz.purs'); | 7 | var baz = require('./Foo/Baz.purs'); |
8 | 8 | ||
9 | var bar = require('./Foo/Bar.purs'); | 9 | console.log(Prelude, test, foo, baz); |
10 | |||
11 | console.log(Prelude, test, foo, baz, bar); | ||
diff --git a/package.json b/package.json index bcf7820..7871a67 100644 --- a/package.json +++ b/package.json | |||
@@ -9,9 +9,11 @@ | |||
9 | "email": "thul.eric@gmail.com" | 9 | "email": "thul.eric@gmail.com" |
10 | }, | 10 | }, |
11 | "scripts": { | 11 | "scripts": { |
12 | "build": "npm run-script build:compile && npm run-script build:package", | 12 | "build": "npm run-script build:compile && npm run-script build:docs && npm run-script build:package", |
13 | "build:compile": "gulp build", | 13 | "build:compile": "./node_modules/.bin/pulp build -o build", |
14 | "build:docs": "./node_modules/.bin/pulp docs", | ||
14 | "build:package": "./node_modules/.bin/webpack --progress --colors --profile --bail", | 15 | "build:package": "./node_modules/.bin/webpack --progress --colors --profile --bail", |
16 | "build:watch": "./node_modules/.bin/pulp -w build -o build", | ||
15 | "build:json": "./node_modules/.bin/webpack --progress --colors --profile --bail --json > index.json", | 17 | "build:json": "./node_modules/.bin/webpack --progress --colors --profile --bail --json > index.json", |
16 | "prepublish": "npm run-script build" | 18 | "prepublish": "npm run-script build" |
17 | }, | 19 | }, |
@@ -19,12 +21,7 @@ | |||
19 | "index.js" | 21 | "index.js" |
20 | ], | 22 | ], |
21 | "devDependencies": { | 23 | "devDependencies": { |
22 | "del": "^1.1.1", | 24 | "pulp": "^4.3.0", |
23 | "gulp": "^3.8.11", | ||
24 | "gulp-plumber": "^1.0.0", | ||
25 | "gulp-purescript": "^0.4.2", | ||
26 | "gulp-util": "^3.0.4", | ||
27 | "run-sequence": "^1.0.2", | ||
28 | "webpack": "^1.8.4" | 25 | "webpack": "^1.8.4" |
29 | }, | 26 | }, |
30 | "dependencies": { | 27 | "dependencies": { |
diff --git a/src/FS.purs b/src/FS.purs deleted file mode 100644 index 6955a63..0000000 --- a/src/FS.purs +++ /dev/null | |||
@@ -1,67 +0,0 @@ | |||
1 | module PursLoader.FS | ||
2 | ( FS() | ||
3 | , writeFileUtf8 | ||
4 | , findFileUtf8 | ||
5 | ) where | ||
6 | |||
7 | import Control.Monad.Aff (Aff(), makeAff) | ||
8 | import Control.Monad.Eff (Eff()) | ||
9 | import Control.Monad.Eff.Exception (Error()) | ||
10 | |||
11 | import Data.Maybe (Maybe(..)) | ||
12 | import Data.String.Regex (Regex()) | ||
13 | |||
14 | import Data.Function | ||
15 | |||
16 | foreign import data FS :: ! | ||
17 | |||
18 | writeFileUtf8 :: forall eff. String -> String -> Aff (fs :: FS | eff) Unit | ||
19 | writeFileUtf8 filepath contents = makeAff $ runFn4 writeFileUtf8Fn filepath contents | ||
20 | |||
21 | foreign import writeFileUtf8Fn """ | ||
22 | function writeFileUtf8Fn(filepath, contents, errback, callback) { | ||
23 | return function(){ | ||
24 | var fs = require('fs'); | ||
25 | |||
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 | |||
38 | findFileUtf8 :: forall eff. Regex -> [String] -> Aff (fs :: FS | eff) (Maybe String) | ||
39 | findFileUtf8 regexp filepaths = makeAff $ runFn6 findFileUtf8Fn Nothing Just regexp filepaths | ||
40 | |||
41 | foreign import findFileUtf8Fn """ | ||
42 | function findFileUtf8Fn(nothing, just, regex, filepaths, errback, callback) { | ||
43 | return function(){ | ||
44 | var fs = require('fs'); | ||
45 | |||
46 | var async = require('async'); | ||
47 | |||
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/Glob.purs b/src/Glob.purs deleted file mode 100644 index 392d9e4..0000000 --- a/src/Glob.purs +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | module PursLoader.Glob | ||
2 | ( Glob() | ||
3 | , globAll | ||
4 | ) where | ||
5 | |||
6 | import Control.Monad.Aff (Aff(), makeAff) | ||
7 | import Control.Monad.Eff (Eff()) | ||
8 | import Control.Monad.Eff.Exception (Error()) | ||
9 | |||
10 | import Data.Function | ||
11 | |||
12 | foreign import data Glob :: ! | ||
13 | |||
14 | globAll :: forall eff. [String] -> Aff (glob :: Glob | eff) [[String]] | ||
15 | globAll patterns = makeAff $ runFn3 globAllFn patterns | ||
16 | |||
17 | foreign import globAllFn """ | ||
18 | function globAllFn(patterns, errback, callback) { | ||
19 | return function(){ | ||
20 | var glob = require('glob'); | ||
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/LoaderRef.purs b/src/LoaderRef.purs deleted file mode 100644 index f1efa04..0000000 --- a/src/LoaderRef.purs +++ /dev/null | |||
@@ -1,74 +0,0 @@ | |||
1 | module PursLoader.LoaderRef | ||
2 | ( LoaderRef() | ||
3 | , Loader() | ||
4 | , async | ||
5 | , cacheable | ||
6 | , query | ||
7 | , clearDependencies | ||
8 | , addDependency | ||
9 | , resourcePath | ||
10 | ) where | ||
11 | |||
12 | import Control.Monad.Eff (Eff()) | ||
13 | import Control.Monad.Eff.Exception (Error()) | ||
14 | |||
15 | import Data.Function (Fn3(), runFn3) | ||
16 | import Data.Maybe (Maybe(), fromMaybe, isJust) | ||
17 | |||
18 | data LoaderRef | ||
19 | |||
20 | foreign import data Loader :: ! | ||
21 | |||
22 | foreign import asyncFn """ | ||
23 | function asyncFn(isJust, fromMaybe, ref){ | ||
24 | return function(){ | ||
25 | var callback = ref.async(); | ||
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 | |||
40 | 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 | ||
42 | |||
43 | foreign import cacheable """ | ||
44 | function cacheable(ref){ | ||
45 | return function(){ | ||
46 | return ref.cacheable && ref.cacheable(); | ||
47 | }; | ||
48 | }""" :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit | ||
49 | |||
50 | foreign import query """ | ||
51 | function query(ref){ | ||
52 | return ref.query; | ||
53 | }""" :: LoaderRef -> String | ||
54 | |||
55 | foreign import clearDependencies """ | ||
56 | function clearDependencies(ref){ | ||
57 | return function(){ | ||
58 | return ref.clearDependencies(); | ||
59 | }; | ||
60 | }""" :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit | ||
61 | |||
62 | foreign import resourcePath """ | ||
63 | function resourcePath(ref){ | ||
64 | return ref.resourcePath; | ||
65 | }""" :: LoaderRef -> String | ||
66 | |||
67 | foreign import addDependency """ | ||
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/LoaderUtil.purs b/src/LoaderUtil.purs deleted file mode 100644 index 86be124..0000000 --- a/src/LoaderUtil.purs +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | module PursLoader.LoaderUtil | ||
2 | ( parseQuery | ||
3 | ) where | ||
4 | |||
5 | import Data.Foreign (Foreign()) | ||
6 | |||
7 | import PursLoader.LoaderRef (LoaderRef()) | ||
8 | |||
9 | foreign import parseQuery """ | ||
10 | function parseQuery(query){ | ||
11 | var loaderUtils = require('loader-utils'); | ||
12 | return loaderUtils.parseQuery(query); | ||
13 | }""" :: String -> Foreign | ||
diff --git a/src/ChildProcess.purs b/src/PursLoader/ChildProcess.js index 34558fa..d62aef6 100644 --- a/src/ChildProcess.purs +++ b/src/PursLoader/ChildProcess.js | |||
@@ -1,24 +1,13 @@ | |||
1 | module PursLoader.ChildProcess | 1 | 'use strict'; |
2 | ( ChildProcess() | ||
3 | , spawn | ||
4 | ) where | ||
5 | 2 | ||
6 | import Control.Monad.Aff (Aff(), makeAff) | 3 | // module PursLoader.ChildProcess |
7 | import Control.Monad.Eff (Eff()) | ||
8 | import Control.Monad.Eff.Exception (Error()) | ||
9 | 4 | ||
10 | import Data.Function | 5 | var child_process = require('child_process'); |
11 | 6 | ||
12 | foreign import data ChildProcess :: ! | 7 | var chalk = require('chalk'); |
13 | 8 | ||
14 | spawn :: forall eff. String -> [String] -> Aff (cp :: ChildProcess | eff) String | ||
15 | spawn command args = makeAff $ runFn4 spawnFn command args | ||
16 | |||
17 | foreign import spawnFn """ | ||
18 | function spawnFn(command, args, errback, callback) { | 9 | function spawnFn(command, args, errback, callback) { |
19 | return function(){ | 10 | return function(){ |
20 | var child_process = require('child_process'); | ||
21 | |||
22 | var process = child_process.spawn(command, args); | 11 | var process = child_process.spawn(command, args); |
23 | 12 | ||
24 | var stdout = new Buffer(0); | 13 | var stdout = new Buffer(0); |
@@ -34,8 +23,6 @@ function spawnFn(command, args, errback, callback) { | |||
34 | }); | 23 | }); |
35 | 24 | ||
36 | process.on('close', function(code){ | 25 | process.on('close', function(code){ |
37 | var chalk = require('chalk'); | ||
38 | |||
39 | var output = stdout.toString('utf-8'); | 26 | var output = stdout.toString('utf-8'); |
40 | 27 | ||
41 | var error = stderr.toString('utf-8'); | 28 | var error = stderr.toString('utf-8'); |
@@ -49,8 +36,5 @@ function spawnFn(command, args, errback, callback) { | |||
49 | }); | 36 | }); |
50 | }; | 37 | }; |
51 | } | 38 | } |
52 | """ :: forall eff. Fn4 String | 39 | |
53 | [String] | 40 | exports.spawnFn = spawnFn; |
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/ChildProcess.purs b/src/PursLoader/ChildProcess.purs new file mode 100644 index 0000000..3bd960b --- /dev/null +++ b/src/PursLoader/ChildProcess.purs | |||
@@ -0,0 +1,23 @@ | |||
1 | module PursLoader.ChildProcess | ||
2 | ( ChildProcess() | ||
3 | , spawn | ||
4 | ) where | ||
5 | |||
6 | import Prelude (Unit(), ($)) | ||
7 | |||
8 | import Control.Monad.Aff (Aff(), makeAff) | ||
9 | import Control.Monad.Eff (Eff()) | ||
10 | import Control.Monad.Eff.Exception (Error()) | ||
11 | |||
12 | import Data.Function | ||
13 | |||
14 | foreign import data ChildProcess :: ! | ||
15 | |||
16 | spawn :: forall eff. String -> Array String -> Aff (cp :: ChildProcess | eff) String | ||
17 | spawn command args = makeAff $ runFn4 spawnFn command args | ||
18 | |||
19 | foreign import spawnFn :: forall eff. Fn4 String | ||
20 | (Array String) | ||
21 | (Error -> Eff (cp :: ChildProcess | eff) Unit) | ||
22 | (String -> Eff (cp :: ChildProcess | eff) Unit) | ||
23 | (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 new file mode 100644 index 0000000..969e3d0 --- /dev/null +++ b/src/PursLoader/FS.purs | |||
@@ -0,0 +1,38 @@ | |||
1 | module PursLoader.FS | ||
2 | ( FS() | ||
3 | , writeFileUtf8 | ||
4 | , findFileUtf8 | ||
5 | ) where | ||
6 | |||
7 | import Prelude (Unit(), ($)) | ||
8 | |||
9 | import Control.Monad.Aff (Aff(), makeAff) | ||
10 | import Control.Monad.Eff (Eff()) | ||
11 | import Control.Monad.Eff.Exception (Error()) | ||
12 | |||
13 | import Data.Maybe (Maybe(..)) | ||
14 | import Data.String.Regex (Regex()) | ||
15 | |||
16 | import Data.Function | ||
17 | |||
18 | foreign import data FS :: ! | ||
19 | |||
20 | writeFileUtf8 :: forall eff. String -> String -> Aff (fs :: FS | eff) Unit | ||
21 | writeFileUtf8 filepath contents = makeAff $ runFn4 writeFileUtf8Fn filepath contents | ||
22 | |||
23 | foreign import writeFileUtf8Fn :: forall eff. Fn4 String | ||
24 | String | ||
25 | (Error -> Eff (fs :: FS | eff) Unit) | ||
26 | (Unit -> Eff (fs :: FS | eff) Unit) | ||
27 | (Eff (fs :: FS | eff) Unit) | ||
28 | |||
29 | findFileUtf8 :: forall eff. Regex -> Array String -> Aff (fs :: FS | eff) (Maybe String) | ||
30 | findFileUtf8 regexp filepaths = makeAff $ runFn6 findFileUtf8Fn Nothing Just regexp filepaths | ||
31 | |||
32 | foreign import findFileUtf8Fn :: forall eff. Fn6 (Maybe String) | ||
33 | (String -> Maybe String) | ||
34 | Regex | ||
35 | (Array String) | ||
36 | (Error -> Eff (fs :: FS | eff) Unit) | ||
37 | (Maybe String -> Eff (fs :: FS | eff) Unit) | ||
38 | (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 new file mode 100644 index 0000000..45eeb56 --- /dev/null +++ b/src/PursLoader/Glob.purs | |||
@@ -0,0 +1,22 @@ | |||
1 | module PursLoader.Glob | ||
2 | ( Glob() | ||
3 | , globAll | ||
4 | ) where | ||
5 | |||
6 | import Prelude (Unit(), ($)) | ||
7 | |||
8 | import Control.Monad.Aff (Aff(), makeAff) | ||
9 | import Control.Monad.Eff (Eff()) | ||
10 | import Control.Monad.Eff.Exception (Error()) | ||
11 | |||
12 | import Data.Function | ||
13 | |||
14 | foreign import data Glob :: ! | ||
15 | |||
16 | globAll :: forall eff. Array String -> Aff (glob :: Glob | eff) (Array (Array String)) | ||
17 | globAll patterns = makeAff $ runFn3 globAllFn patterns | ||
18 | |||
19 | foreign import globAllFn :: forall eff. Fn3 (Array String) | ||
20 | (Error -> Eff (glob :: Glob | eff) Unit) | ||
21 | ((Array (Array String)) -> Eff (glob :: Glob | eff) Unit) | ||
22 | (Eff (glob :: Glob | eff) Unit) | ||
diff --git a/src/PursLoader/Loader.js b/src/PursLoader/Loader.js new file mode 100644 index 0000000..98459b6 --- /dev/null +++ b/src/PursLoader/Loader.js | |||
@@ -0,0 +1,19 @@ | |||
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; | ||
18 | |||
19 | exports.resolve = path.resolve; | ||
diff --git a/src/Loader.purs b/src/PursLoader/Loader.purs index e9e03c4..3cb99cd 100644 --- a/src/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) |
@@ -14,6 +16,7 @@ import Data.Function (Fn2(), mkFn2) | |||
14 | import Data.Maybe (Maybe(..), fromMaybe, maybe) | 16 | import Data.Maybe (Maybe(..), fromMaybe, maybe) |
15 | import Data.String (joinWith) | 17 | import Data.String (joinWith) |
16 | import Data.String.Regex (match, noFlags, regex, test) | 18 | import Data.String.Regex (match, noFlags, regex, test) |
19 | import Data.Traversable (sequence) | ||
17 | 20 | ||
18 | import PursLoader.ChildProcess (ChildProcess(), spawn) | 21 | import PursLoader.ChildProcess (ChildProcess(), spawn) |
19 | import PursLoader.FS (FS(), writeFileUtf8, findFileUtf8) | 22 | import PursLoader.FS (FS(), writeFileUtf8, findFileUtf8) |
@@ -36,18 +39,13 @@ psciFilename = ".psci" | |||
36 | 39 | ||
37 | (!!!) = flip (!!) | 40 | (!!!) = flip (!!) |
38 | 41 | ||
39 | foreign import cwd "var cwd = process.cwd();" :: String | 42 | foreign import cwd :: String |
43 | |||
44 | foreign import relative :: String -> String -> String | ||
40 | 45 | ||
41 | foreign import relative """ | 46 | foreign import resolve :: 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 | 47 | ||
50 | mkPsci :: [[String]] -> [[String]] -> String | 48 | mkPsci :: Array (Array String) -> Array (Array String) -> String |
51 | mkPsci srcs ffis = joinWith "\n" ((loadModule <$> concat srcs) <> (loadForeign <$> concat ffis)) | 49 | mkPsci srcs ffis = joinWith "\n" ((loadModule <$> concat srcs) <> (loadForeign <$> concat ffis)) |
52 | where | 50 | where |
53 | loadModule :: String -> String | 51 | loadModule :: String -> String |
@@ -56,7 +54,7 @@ mkPsci srcs ffis = joinWith "\n" ((loadModule <$> concat srcs) <> (loadForeign < | |||
56 | loadForeign :: String -> String | 54 | loadForeign :: String -> String |
57 | loadForeign a = ":f " ++ relative cwd a | 55 | loadForeign a = ":f " ++ relative cwd a |
58 | 56 | ||
59 | findFFI :: forall eff. [[String]] -> String -> Aff (fs :: FS | eff) (Maybe String) | 57 | findFFI :: forall eff. Array (Array String) -> String -> Aff (fs :: FS | eff) (Maybe String) |
60 | findFFI ffiss name = findFileUtf8 re (concat ffiss) | 58 | findFFI ffiss name = findFileUtf8 re (concat ffiss) |
61 | where | 59 | where |
62 | re = regex ("(?:^|\\n)//\\s*module\\s*" ++ name ++ "\\s*\\n") noFlags | 60 | re = regex ("(?:^|\\n)//\\s*module\\s*" ++ name ++ "\\s*\\n") noFlags |
@@ -79,12 +77,13 @@ loader' ref source = do | |||
79 | 77 | ||
80 | writeFileUtf8 psciFilename psciFile | 78 | writeFileUtf8 psciFilename psciFile |
81 | 79 | ||
82 | let moduleName = match moduleRegex source >>= (!!!) 1 | 80 | let moduleName = match moduleRegex source >>= (!!!) 1 >>= id |
83 | hasForeign = test foreignRegex source | 81 | hasForeign = test foreignRegex source |
84 | result = (\a -> "module.exports = require('" ++ a ++ "');") <$> moduleName | 82 | result = (\a -> "module.exports = require('" ++ a ++ "');") <$> moduleName |
85 | 83 | ||
86 | liftEff (clearDependencies ref) | 84 | liftEff (clearDependencies ref) |
87 | liftEff (addDependency ref (resourcePath ref)) | 85 | liftEff (addDependency ref (resourcePath ref)) |
86 | liftEff (sequence $ (\src -> addDependency ref (resolve src)) <$> concat srcss) | ||
88 | 87 | ||
89 | foreignPath <- if hasForeign | 88 | foreignPath <- if hasForeign |
90 | then fromMaybe (pure Nothing) (findFFI ffiss <$> moduleName) | 89 | then fromMaybe (pure Nothing) (findFFI ffiss <$> moduleName) |
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 new file mode 100644 index 0000000..33c4f7e --- /dev/null +++ b/src/PursLoader/LoaderRef.purs | |||
@@ -0,0 +1,40 @@ | |||
1 | module PursLoader.LoaderRef | ||
2 | ( LoaderRef() | ||
3 | , Loader() | ||
4 | , async | ||
5 | , cacheable | ||
6 | , query | ||
7 | , clearDependencies | ||
8 | , addDependency | ||
9 | , resourcePath | ||
10 | ) where | ||
11 | |||
12 | import Prelude (Unit()) | ||
13 | |||
14 | import Control.Monad.Eff (Eff()) | ||
15 | import Control.Monad.Eff.Exception (Error()) | ||
16 | |||
17 | import Data.Function (Fn3(), runFn3) | ||
18 | import Data.Maybe (Maybe(), fromMaybe, isJust) | ||
19 | |||
20 | data LoaderRef | ||
21 | |||
22 | foreign import data Loader :: ! | ||
23 | |||
24 | foreign import asyncFn :: forall eff a. Fn3 (Maybe Error -> Boolean) | ||
25 | (Error -> Maybe Error -> Error) | ||
26 | LoaderRef | ||
27 | (Eff (loader :: Loader | eff) (Maybe Error -> a -> Eff (loader :: Loader | eff) Unit)) | ||
28 | |||
29 | async :: forall eff a. LoaderRef -> Eff (loader :: Loader | eff) (Maybe Error -> a -> Eff (loader :: Loader | eff) Unit) | ||
30 | async ref = runFn3 asyncFn isJust fromMaybe ref | ||
31 | |||
32 | foreign import cacheable :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit | ||
33 | |||
34 | foreign import query :: LoaderRef -> String | ||
35 | |||
36 | foreign import clearDependencies :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit | ||
37 | |||
38 | foreign import resourcePath :: LoaderRef -> String | ||
39 | |||
40 | foreign import addDependency :: 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 new file mode 100644 index 0000000..3e5a7bc --- /dev/null +++ b/src/PursLoader/LoaderUtil.purs | |||
@@ -0,0 +1,9 @@ | |||
1 | module PursLoader.LoaderUtil | ||
2 | ( parseQuery | ||
3 | ) where | ||
4 | |||
5 | import Data.Foreign (Foreign()) | ||
6 | |||
7 | import PursLoader.LoaderRef (LoaderRef()) | ||
8 | |||
9 | foreign import parseQuery :: String -> Foreign | ||
diff --git a/src/Options.purs b/src/PursLoader/Options.purs index 51e9be5..e3957eb 100644 --- a/src/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) |