@@ -5,6 +5,8 @@ module GulpPurescript.Options
55 , pscDocsOptions
66 ) where
77
8+ import Control.Alt ((<|>))
9+
810import Data.Array (concat )
911import Data.Either (Either (..), either )
1012import Data.Foreign (Foreign (), ForeignError (TypeMismatch), F ())
@@ -74,8 +76,7 @@ newtype Psc
7476 = Psc { noPrelude :: NullOrUndefined Boolean
7577 , noTco :: NullOrUndefined Boolean
7678 , noMagicDo :: NullOrUndefined Boolean
77- , mainNoArg :: NullOrUndefined Boolean
78- , mainWithArg :: NullOrUndefined String
79+ , main :: NullOrUndefined (Either Boolean String )
7980 , noOpts :: NullOrUndefined Boolean
8081 , verboseErrors :: NullOrUndefined Boolean
8182 , comments :: NullOrUndefined Boolean
@@ -103,28 +104,30 @@ newtype PscDocs
103104
104105data Format = Markdown | ETags | CTags
105106
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+
106111instance isForeignPsc :: IsForeign Psc where
107112 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 ->
109114 Psc { noPrelude: a
110115 , noTco: b
111116 , 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
123127 }) <$> readProp noPreludeKey obj
124128 <*> readProp noTcoKey obj
125129 <*> readProp noMagicDoKey obj
126130 <*> readProp mainKey obj
127- <*> readProp mainKey obj
128131 <*> readProp noOptsKey obj
129132 <*> readProp verboseErrorsKey obj
130133 <*> readProp commentsKey obj
@@ -171,6 +174,11 @@ mkBoolean key opt = maybe [] (\a -> if a then ["--" ++ key] else []) (runNullOrU
171174mkString :: String -> NullOrUndefined String -> [String ]
172175mkString key opt = maybe [] (\a -> [" --" ++ key ++ " =" ++ a]) (runNullOrUndefined opt)
173176
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+
174182mkStringArray :: String -> NullOrUndefined [String ] -> [String ]
175183mkStringArray key opt = concat $ mkString key <$> (NullOrUndefined <<< Just )
176184 <$> (fromMaybe [] $ runNullOrUndefined opt)
@@ -187,8 +195,7 @@ foldPscOptions :: Psc -> [String]
187195foldPscOptions (Psc a) = mkBoolean noPreludeOpt a.noPrelude <>
188196 mkBoolean noTcoOpt a.noTco <>
189197 mkBoolean noMagicDoOpt a.noMagicDo <>
190- mkBoolean mainOpt a.mainNoArg <>
191- mkString mainOpt a.mainWithArg <>
198+ mkBooleanString mainOpt a.main <>
192199 mkBoolean noOptsOpt a.noOpts <>
193200 mkBoolean verboseErrorsOpt a.verboseErrors <>
194201 mkBoolean commentsOpt a.comments <>
0 commit comments