diff options
author | eric thul <thul.eric@gmail.com> | 2015-05-14 22:13:59 -0400 |
---|---|---|
committer | eric thul <thul.eric@gmail.com> | 2015-05-14 22:13:59 -0400 |
commit | a72c8af19a72186069465c139b72df9c353fd3d1 (patch) | |
tree | ecb69055fe7b668b99d49153c12c729938ed08dc /src/Options.purs | |
parent | a8b2571ee98ccd640a39873f8a9d67c707f336fe (diff) | |
download | purs-loader-a72c8af19a72186069465c139b72df9c353fd3d1.tar.gz purs-loader-a72c8af19a72186069465c139b72df9c353fd3d1.tar.zst purs-loader-a72c8af19a72186069465c139b72df9c353fd3d1.zip |
Additional loader options
Adds the `psc-make` options `comments` and `no-prefix`. Also, an
internal option `src` has been added that is used to specify the source
paths of `PureScript` files that will be globbed for compilation.
By default the `bower_components` path is globbed, but the loader
requires that the source paths be provided for the user's code.
Resolves #12
Diffstat (limited to 'src/Options.purs')
-rw-r--r-- | src/Options.purs | 77 |
1 files changed, 52 insertions, 25 deletions
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) | ||