Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"purescript-arrays": "0.3.7",
"purescript-transformers": "0.5.5",
"purescript-monad-eff": "0.1.0",
"purescript-tuples": "0.3.4"
"purescript-tuples": "0.3.4",
"purescript-control": "0.2.6"
}
}
41 changes: 24 additions & 17 deletions src/Options.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module GulpPurescript.Options
, pscDocsOptions
) where

import Control.Alt ((<|>))

import Data.Array (concat)
import Data.Either (Either(..), either)
import Data.Foreign (Foreign(), ForeignError(TypeMismatch), F())
Expand Down Expand Up @@ -74,8 +76,7 @@ newtype Psc
= Psc { noPrelude :: NullOrUndefined Boolean
, noTco :: NullOrUndefined Boolean
, noMagicDo :: NullOrUndefined Boolean
, mainNoArg :: NullOrUndefined Boolean
, mainWithArg :: NullOrUndefined String
, main :: NullOrUndefined (Either Boolean String)
, noOpts :: NullOrUndefined Boolean
, verboseErrors :: NullOrUndefined Boolean
, comments :: NullOrUndefined Boolean
Expand Down Expand Up @@ -103,28 +104,30 @@ newtype PscDocs

data Format = Markdown | ETags | CTags

instance isForeignEither :: (IsForeign a, IsForeign b) => IsForeign (Either a b) where
read a = (Left <$> read a :: F a) <|>
(Right <$> read a :: F b)

instance isForeignPsc :: IsForeign Psc where
read obj =
(\a b c d e f g h i j k l m n ->
(\a b c d e f g h i j k l m ->
Psc { noPrelude: a
, noTco: b
, noMagicDo: c
, mainNoArg: d
, mainWithArg: e
, noOpts: f
, verboseErrors: g
, comments: h
, browserNamespace: i
, "module": j
, codegen: k
, output: l
, externs: m
, noPrefix: n
, main: d
, noOpts: e
, verboseErrors: f
, comments: g
, browserNamespace: h
, "module": i
, codegen: j
, output: k
, externs: l
, noPrefix: m
}) <$> readProp noPreludeKey obj
<*> readProp noTcoKey obj
<*> readProp noMagicDoKey obj
<*> readProp mainKey obj
<*> readProp mainKey obj
<*> readProp noOptsKey obj
<*> readProp verboseErrorsKey obj
<*> readProp commentsKey obj
Expand Down Expand Up @@ -171,6 +174,11 @@ mkBoolean key opt = maybe [] (\a -> if a then ["--" ++ key] else []) (runNullOrU
mkString :: String -> NullOrUndefined String -> [String]
mkString key opt = maybe [] (\a -> ["--" ++ key ++ "=" ++ a]) (runNullOrUndefined opt)

mkBooleanString :: String -> NullOrUndefined (Either Boolean String) -> [String]
mkBooleanString key opt = maybe [] (either (\a -> mkBoolean key (NullOrUndefined $ Just a))
(\a -> mkString key (NullOrUndefined $ Just a)))
(runNullOrUndefined opt)

mkStringArray :: String -> NullOrUndefined [String] -> [String]
mkStringArray key opt = concat $ mkString key <$> (NullOrUndefined <<< Just)
<$> (fromMaybe [] $ runNullOrUndefined opt)
Expand All @@ -187,8 +195,7 @@ foldPscOptions :: Psc -> [String]
foldPscOptions (Psc a) = mkBoolean noPreludeOpt a.noPrelude <>
mkBoolean noTcoOpt a.noTco <>
mkBoolean noMagicDoOpt a.noMagicDo <>
mkBoolean mainOpt a.mainNoArg <>
mkString mainOpt a.mainWithArg <>
mkBooleanString mainOpt a.main <>
mkBoolean noOptsOpt a.noOpts <>
mkBoolean verboseErrorsOpt a.verboseErrors <>
mkBoolean commentsOpt a.comments <>
Expand Down