@@ -5,6 +5,8 @@ module GulpPurescript.Options
5
5
, pscDocsOptions
6
6
) where
7
7
8
+ import Control.Alt ((<|>))
9
+
8
10
import Data.Array (concat )
9
11
import Data.Either (Either (..), either )
10
12
import Data.Foreign (Foreign (), ForeignError (TypeMismatch), F ())
@@ -74,8 +76,7 @@ newtype Psc
74
76
= Psc { noPrelude :: NullOrUndefined Boolean
75
77
, noTco :: NullOrUndefined Boolean
76
78
, noMagicDo :: NullOrUndefined Boolean
77
- , mainNoArg :: NullOrUndefined Boolean
78
- , mainWithArg :: NullOrUndefined String
79
+ , main :: NullOrUndefined (Either Boolean String )
79
80
, noOpts :: NullOrUndefined Boolean
80
81
, verboseErrors :: NullOrUndefined Boolean
81
82
, comments :: NullOrUndefined Boolean
@@ -103,28 +104,30 @@ newtype PscDocs
103
104
104
105
data Format = Markdown | ETags | CTags
105
106
107
+ instance isForeignEither :: (IsForeign a , IsForeign b ) => IsForeign (Either a b ) where
108
+ read a = (Left <$> read a :: F a ) <|>
109
+ (Right <$> read a :: F b )
110
+
106
111
instance isForeignPsc :: IsForeign Psc where
107
112
read obj =
108
- (\a b c d e f g h i j k l m n ->
113
+ (\a b c d e f g h i j k l m ->
109
114
Psc { noPrelude: a
110
115
, noTco: b
111
116
, noMagicDo: c
112
- , mainNoArg: d
113
- , mainWithArg: e
114
- , noOpts: f
115
- , verboseErrors: g
116
- , comments: h
117
- , browserNamespace: i
118
- , " module" : j
119
- , codegen: k
120
- , output: l
121
- , externs: m
122
- , noPrefix: n
117
+ , main: d
118
+ , noOpts: e
119
+ , verboseErrors: f
120
+ , comments: g
121
+ , browserNamespace: h
122
+ , " module" : i
123
+ , codegen: j
124
+ , output: k
125
+ , externs: l
126
+ , noPrefix: m
123
127
}) <$> readProp noPreludeKey obj
124
128
<*> readProp noTcoKey obj
125
129
<*> readProp noMagicDoKey obj
126
130
<*> readProp mainKey obj
127
- <*> readProp mainKey obj
128
131
<*> readProp noOptsKey obj
129
132
<*> readProp verboseErrorsKey obj
130
133
<*> readProp commentsKey obj
@@ -171,6 +174,11 @@ mkBoolean key opt = maybe [] (\a -> if a then ["--" ++ key] else []) (runNullOrU
171
174
mkString :: String -> NullOrUndefined String -> [String ]
172
175
mkString key opt = maybe [] (\a -> [" --" ++ key ++ " =" ++ a]) (runNullOrUndefined opt)
173
176
177
+ mkBooleanString :: String -> NullOrUndefined (Either Boolean String ) -> [String ]
178
+ mkBooleanString key opt = maybe [] (either (\a -> mkBoolean key (NullOrUndefined $ Just a))
179
+ (\a -> mkString key (NullOrUndefined $ Just a)))
180
+ (runNullOrUndefined opt)
181
+
174
182
mkStringArray :: String -> NullOrUndefined [String ] -> [String ]
175
183
mkStringArray key opt = concat $ mkString key <$> (NullOrUndefined <<< Just )
176
184
<$> (fromMaybe [] $ runNullOrUndefined opt)
@@ -187,8 +195,7 @@ foldPscOptions :: Psc -> [String]
187
195
foldPscOptions (Psc a) = mkBoolean noPreludeOpt a.noPrelude <>
188
196
mkBoolean noTcoOpt a.noTco <>
189
197
mkBoolean noMagicDoOpt a.noMagicDo <>
190
- mkBoolean mainOpt a.mainNoArg <>
191
- mkString mainOpt a.mainWithArg <>
198
+ mkBooleanString mainOpt a.main <>
192
199
mkBoolean noOptsOpt a.noOpts <>
193
200
mkBoolean verboseErrorsOpt a.verboseErrors <>
194
201
mkBoolean commentsOpt a.comments <>
0 commit comments