Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 46e9b8b

Browse files
committed
Merge pull request #25 from purescript-contrib/topic/issue-24
Refactoring underlying main option type
2 parents 8738dc4 + df3f8f9 commit 46e9b8b

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

bower.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"purescript-arrays": "0.3.7",
1111
"purescript-transformers": "0.5.5",
1212
"purescript-monad-eff": "0.1.0",
13-
"purescript-tuples": "0.3.4"
13+
"purescript-tuples": "0.3.4",
14+
"purescript-control": "0.2.6"
1415
}
1516
}

src/Options.purs

+24-17
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ module GulpPurescript.Options
55
, pscDocsOptions
66
) where
77

8+
import Control.Alt ((<|>))
9+
810
import Data.Array (concat)
911
import Data.Either (Either(..), either)
1012
import 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

104105
data 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+
106111
instance 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
171174
mkString :: String -> NullOrUndefined String -> [String]
172175
mkString 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+
174182
mkStringArray :: String -> NullOrUndefined [String] -> [String]
175183
mkStringArray key opt = concat $ mkString key <$> (NullOrUndefined <<< Just)
176184
<$> (fromMaybe [] $ runNullOrUndefined opt)
@@ -187,8 +195,7 @@ foldPscOptions :: Psc -> [String]
187195
foldPscOptions (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

Comments
 (0)