diff options
-rw-r--r-- | MODULE.md | 21 | ||||
-rw-r--r-- | README.md | 47 | ||||
-rw-r--r-- | example/webpack.config.js | 2 | ||||
-rw-r--r-- | src/Loader.purs | 10 | ||||
-rw-r--r-- | src/Options.purs | 77 |
5 files changed, 114 insertions, 43 deletions
@@ -177,6 +177,20 @@ instance isForeignOptions :: IsForeign Options | |||
177 | ``` | 177 | ``` |
178 | 178 | ||
179 | 179 | ||
180 | #### `booleanLoaderOption` | ||
181 | |||
182 | ``` purescript | ||
183 | instance booleanLoaderOption :: LoaderOption Boolean | ||
184 | ``` | ||
185 | |||
186 | |||
187 | #### `stringLoaderOption` | ||
188 | |||
189 | ``` purescript | ||
190 | instance stringLoaderOption :: LoaderOption String | ||
191 | ``` | ||
192 | |||
193 | |||
180 | #### `pscMakeOutputOption` | 194 | #### `pscMakeOutputOption` |
181 | 195 | ||
182 | ``` purescript | 196 | ``` purescript |
@@ -191,6 +205,13 @@ pscMakeOptions :: Foreign -> [String] | |||
191 | ``` | 205 | ``` |
192 | 206 | ||
193 | 207 | ||
208 | #### `loaderSrcOption` | ||
209 | |||
210 | ``` purescript | ||
211 | loaderSrcOption :: Foreign -> Maybe [String] | ||
212 | ``` | ||
213 | |||
214 | |||
194 | 215 | ||
195 | ## Module PursLoader.Path | 216 | ## Module PursLoader.Path |
196 | 217 | ||
@@ -12,18 +12,41 @@ npm install purs-loader --save-dev | |||
12 | 12 | ||
13 | ## Options | 13 | ## Options |
14 | 14 | ||
15 | - **no-prelude**: Boolean value that toggles `--no-prelude` | 15 | ###### `noPrelude` (Boolean) |
16 | - Do not include the Prelude in the generated Javascript. | 16 | |
17 | - **no-opts**: Boolean value that toggles `--no-opts` | 17 | Toggles `--no-prelude` that omits the Prelude. |
18 | - Disable all optimizations. | 18 | |
19 | - **no-magic-do**: Boolean value that toggles `--no-magic-do` | 19 | ###### `noTco` (Boolean) |
20 | - Turn off optimizations which inline calls to >>= for the Eff monad. | 20 | |
21 | - **no-tco**: Boolean value that toggles `--no-tco` | 21 | Toggles `--no-tco` that disables tail-call optimizations. |
22 | - Turn off tail-call elimination. | 22 | |
23 | - **verbose-errors**: Boolean value that toggles `--verbose-errors` | 23 | ###### `noMagicDo` (Boolean) |
24 | - Generate verbose error messages. | 24 | |
25 | - **output**: String value that sets `--output=<string>` | 25 | Toggles `--no-magic-do` that disables optimizations overloading the do keyword generating efficient code for the `Eff` monad. |
26 | - Write the generated Javascript to the specified file. | 26 | |
27 | ###### `noOpts` (Boolean) | ||
28 | |||
29 | Toggles `--no-opts` that skips the optimization phase. | ||
30 | |||
31 | ###### `verboseErrors` (Boolean) | ||
32 | |||
33 | Toggles `--verbose-errors` that displays verbose error messages. | ||
34 | |||
35 | ###### `comments` (Boolean) | ||
36 | |||
37 | Toggles `--comments` that includes comments in generated code. | ||
38 | |||
39 | ###### `output` (String) | ||
40 | |||
41 | Sets `--output=<string>` the specifies the output directory, `output` by default. | ||
42 | |||
43 | ###### `noPrefix` (Boolean) | ||
44 | |||
45 | Toggles `--no-prefix` that does not include the comment header. | ||
46 | |||
47 | ###### `src` (String Array) | ||
48 | |||
49 | Specifies PureScript source paths to be globbed for `.purs` files. By default, `bower_components` is search. Additional paths may be specified using this option. This option is specified as `src[]=path`. | ||
27 | 50 | ||
28 | ## Example | 51 | ## Example |
29 | 52 | ||
diff --git a/example/webpack.config.js b/example/webpack.config.js index 19997f3..f67e83a 100644 --- a/example/webpack.config.js +++ b/example/webpack.config.js | |||
@@ -5,7 +5,7 @@ var config | |||
5 | , output: { path: __dirname | 5 | , output: { path: __dirname |
6 | , filename: 'bundle.js' | 6 | , filename: 'bundle.js' |
7 | } | 7 | } |
8 | , module: { loaders: [ { test: /\.purs$/, loader: 'purs-loader' } ] } | 8 | , module: { loaders: [ { test: /\.purs$/, loader: 'purs-loader?src[]=src' } ] } |
9 | , resolve: { modulesDirectories: [ 'node_modules', | 9 | , resolve: { modulesDirectories: [ 'node_modules', |
10 | 'output' | 10 | 'output' |
11 | ] | 11 | ] |
diff --git a/src/Loader.purs b/src/Loader.purs index aae51c0..fedc424 100644 --- a/src/Loader.purs +++ b/src/Loader.purs | |||
@@ -26,7 +26,7 @@ import PursLoader.Glob (Glob(), glob) | |||
26 | import PursLoader.LoaderRef (LoaderRef(), Loader(), async, cacheable, clearDependencies, addDependency, query, resourcePath) | 26 | import PursLoader.LoaderRef (LoaderRef(), Loader(), async, cacheable, clearDependencies, addDependency, query, resourcePath) |
27 | import PursLoader.LoaderUtil (getRemainingRequest, parseQuery) | 27 | import PursLoader.LoaderUtil (getRemainingRequest, parseQuery) |
28 | import PursLoader.OS (eol) | 28 | import PursLoader.OS (eol) |
29 | import PursLoader.Options (pscMakeOptions, pscMakeDefaultOutput, pscMakeOutputOption) | 29 | import PursLoader.Options (loaderSrcOption, pscMakeOptions, pscMakeDefaultOutput, pscMakeOutputOption) |
30 | import PursLoader.Path (dirname, join, relative, resolve) | 30 | import PursLoader.Path (dirname, join, relative, resolve) |
31 | 31 | ||
32 | foreign import cwd "var cwd = process.cwd();" :: String | 32 | foreign import cwd "var cwd = process.cwd();" :: String |
@@ -43,8 +43,8 @@ indexFilename = "index.js" | |||
43 | 43 | ||
44 | (!!!) = flip (!!) | 44 | (!!!) = flip (!!) |
45 | 45 | ||
46 | pursPattern :: String -> String | 46 | pursPattern :: [String] -> String |
47 | pursPattern root = join [ "{" ++ joinWith "," [ bowerPattern, root ] ++ "}" | 47 | pursPattern srcs = join [ "{" ++ joinWith "," ([ bowerPattern ] <> srcs) ++ "}" |
48 | , "**" | 48 | , "**" |
49 | , "*.purs" | 49 | , "*.purs" |
50 | ] | 50 | ] |
@@ -86,10 +86,10 @@ loader' ref source = do | |||
86 | liftEff $ cacheable ref | 86 | liftEff $ cacheable ref |
87 | 87 | ||
88 | let request = getRemainingRequest ref | 88 | let request = getRemainingRequest ref |
89 | root = dirname $ relative cwd request | ||
90 | parsed = parseQuery $ query ref | 89 | parsed = parseQuery $ query ref |
90 | srcs = loaderSrcOption parsed | ||
91 | opts = pscMakeOptions parsed | 91 | opts = pscMakeOptions parsed |
92 | pattern = pursPattern root | 92 | pattern = pursPattern $ fromMaybe [] srcs |
93 | key = match moduleRegex source >>= (!!!) 1 | 93 | key = match moduleRegex source >>= (!!!) 1 |
94 | 94 | ||
95 | files <- glob pattern | 95 | files <- glob pattern |
diff --git a/src/Options.purs b/src/Options.purs index b96cddc..c47bebc 100644 --- a/src/Options.purs +++ b/src/Options.purs | |||
@@ -2,6 +2,7 @@ module PursLoader.Options | |||
2 | ( pscMakeOptions | 2 | ( pscMakeOptions |
3 | , pscMakeDefaultOutput | 3 | , pscMakeDefaultOutput |
4 | , pscMakeOutputOption | 4 | , pscMakeOutputOption |
5 | , loaderSrcOption | ||
5 | ) where | 6 | ) where |
6 | 7 | ||
7 | import Data.Either (either) | 8 | import Data.Either (either) |
@@ -24,6 +25,12 @@ verboseErrorsOpt = "verbose-errors" | |||
24 | 25 | ||
25 | outputOpt = "output" | 26 | outputOpt = "output" |
26 | 27 | ||
28 | commentsOpt = "comments" | ||
29 | |||
30 | noPrefixOpt = "no-prefix" | ||
31 | |||
32 | srcOpt = "src" | ||
33 | |||
27 | pscMakeDefaultOutput = "output" | 34 | pscMakeDefaultOutput = "output" |
28 | 35 | ||
29 | newtype Options | 36 | newtype Options |
@@ -32,29 +39,42 @@ newtype Options | |||
32 | , noMagicDo :: NullOrUndefined Boolean | 39 | , noMagicDo :: NullOrUndefined Boolean |
33 | , noTco :: NullOrUndefined Boolean | 40 | , noTco :: NullOrUndefined Boolean |
34 | , verboseErrors :: NullOrUndefined Boolean | 41 | , verboseErrors :: NullOrUndefined Boolean |
42 | , comments :: NullOrUndefined Boolean | ||
35 | , output :: NullOrUndefined String | 43 | , output :: NullOrUndefined String |
44 | , noPrefix :: NullOrUndefined Boolean | ||
45 | , src :: NullOrUndefined [String] | ||
36 | } | 46 | } |
37 | 47 | ||
38 | instance isForeignOptions :: IsForeign Options where | 48 | instance isForeignOptions :: IsForeign Options where |
39 | read obj = (\a b c d e f -> | 49 | read obj = Options <$> ({ noPrelude: _ |
40 | Options { noPrelude: a | 50 | , noOpts: _ |
41 | , noOpts: b | 51 | , noMagicDo: _ |
42 | , noMagicDo: c | 52 | , noTco: _ |
43 | , noTco: d | 53 | , verboseErrors: _ |
44 | , verboseErrors: e | 54 | , comments: _ |
45 | , output: f | 55 | , output: _ |
46 | }) <$> readProp noPreludeOpt obj | 56 | , noPrefix: _ |
47 | <*> readProp noOptsOpt obj | 57 | , src: _ |
48 | <*> readProp noMagicDoOpt obj | 58 | } <$> readProp noPreludeOpt obj |
49 | <*> readProp noTcoOpt obj | 59 | <*> readProp noOptsOpt obj |
50 | <*> readProp verboseErrorsOpt obj | 60 | <*> readProp noMagicDoOpt obj |
51 | <*> readProp outputOpt obj | 61 | <*> readProp noTcoOpt obj |
52 | 62 | <*> readProp verboseErrorsOpt obj | |
53 | booleanOpt :: String -> NullOrUndefined Boolean -> [String] | 63 | <*> readProp commentsOpt obj |
54 | booleanOpt key opt = maybe [] (\a -> if a then ["--" ++ key] else []) (runNullOrUndefined opt) | 64 | <*> readProp outputOpt obj |
55 | 65 | <*> readProp noPrefixOpt obj | |
56 | stringOpt :: String -> NullOrUndefined String -> [String] | 66 | <*> readProp srcOpt obj) |
57 | stringOpt key opt = maybe [] (\a -> ["--" ++ key ++ "=" ++ a]) (runNullOrUndefined opt) | 67 | |
68 | class LoaderOption a where | ||
69 | opt :: String -> NullOrUndefined a -> [String] | ||
70 | |||
71 | instance booleanLoaderOption :: LoaderOption Boolean where | ||
72 | opt key opt = maybe [] (\a -> if a then ["--" ++ key] else []) | ||
73 | (runNullOrUndefined opt) | ||
74 | |||
75 | instance stringLoaderOption :: LoaderOption String where | ||
76 | opt key opt = maybe [] (\a -> ["--" ++ key ++ "=" ++ a]) | ||
77 | (runNullOrUndefined opt) | ||
58 | 78 | ||
59 | pscMakeOutputOption :: Foreign -> Maybe String | 79 | pscMakeOutputOption :: Foreign -> Maybe String |
60 | pscMakeOutputOption query = either (const Nothing) | 80 | pscMakeOutputOption query = either (const Nothing) |
@@ -64,9 +84,16 @@ pscMakeOutputOption query = either (const Nothing) | |||
64 | pscMakeOptions :: Foreign -> [String] | 84 | pscMakeOptions :: Foreign -> [String] |
65 | pscMakeOptions query = either (const []) fold parsed | 85 | pscMakeOptions query = either (const []) fold parsed |
66 | where parsed = read query :: F Options | 86 | where parsed = read query :: F Options |
67 | fold (Options a) = booleanOpt noPreludeOpt a.noPrelude <> | 87 | fold (Options a) = opt noPreludeOpt a.noPrelude <> |
68 | booleanOpt noOptsOpt a.noOpts <> | 88 | opt noOptsOpt a.noOpts <> |
69 | booleanOpt noMagicDoOpt a.noMagicDo <> | 89 | opt noMagicDoOpt a.noMagicDo <> |
70 | booleanOpt noTcoOpt a.noTco <> | 90 | opt noTcoOpt a.noTco <> |
71 | booleanOpt verboseErrorsOpt a.verboseErrors <> | 91 | opt verboseErrorsOpt a.verboseErrors <> |
72 | stringOpt outputOpt a.output | 92 | opt commentsOpt a.comments <> |
93 | opt outputOpt a.output <> | ||
94 | opt noPrefixOpt a.noPrefix | ||
95 | |||
96 | loaderSrcOption :: Foreign -> Maybe [String] | ||
97 | loaderSrcOption query = either (const Nothing) | ||
98 | (\(Options a) -> runNullOrUndefined a.src) | ||
99 | (read query) | ||