]> git.immae.eu Git - github/fretlink/purs-loader.git/blobdiff - src/PursLoader/Options.purs
Updating bundle output option name
[github/fretlink/purs-loader.git] / src / PursLoader / Options.purs
index e3957ebc9c69a4c838c69dfcbb18535ebe82fafc..706ddd240b0bf74d0a837f515799c236b553745d 100644 (file)
 module PursLoader.Options
-  ( pscOptions
-  , loaderSrcOption
-  , loaderFFIOption
+  ( Options()
+  , runOptions
   ) where
 
-import Prelude (Unit(), (<>), (<$>), (<<<), (++), (<*>), const)
+import Prelude ((<$>), (<<<), id)
 
-import Data.Array (concat)
-import Data.Either (either)
+import Data.Foreign.Class (IsForeign, readProp)
+import Data.Foreign.NullOrUndefined (runNullOrUndefined)
+import Data.Maybe (maybe)
 
-import Data.Foreign (Foreign(), F())
-import Data.Foreign.Class (IsForeign, read, readProp)
-import Data.Foreign.NullOrUndefined (NullOrUndefined(..), runNullOrUndefined)
+import PursLoader.Path (joinPath)
 
-import Data.Maybe (Maybe(..), maybe, fromMaybe)
+newtype Options = Options { bundleOutput :: String }
 
-noPreludeOpt = "no-prelude"
+type Options_ = { bundleOutput :: String }
 
-noOptsOpt = "no-opts"
-
-noMagicDoOpt = "no-magic-do"
-
-noTcoOpt = "no-tco"
-
-verboseErrorsOpt = "verbose-errors"
-
-outputOpt = "output"
-
-commentsOpt = "comments"
-
-noPrefixOpt = "no-prefix"
-
-requirePathOpt = "require-path"
-
-srcOpt = "src"
-
-ffiOpt = "ffi"
-
-newtype Options
-  = Options { noPrelude :: NullOrUndefined Boolean
-            , noOpts :: NullOrUndefined Boolean
-            , noMagicDo :: NullOrUndefined Boolean
-            , noTco :: NullOrUndefined Boolean
-            , verboseErrors :: NullOrUndefined Boolean
-            , comments :: NullOrUndefined Boolean
-            , output :: NullOrUndefined String
-            , noPrefix :: NullOrUndefined Boolean
-            , requirePath :: NullOrUndefined String
-            , src :: NullOrUndefined (Array String)
-            , ffi :: NullOrUndefined (Array String)
-            }
+runOptions :: Options -> Options_
+runOptions (Options options) = options
 
 instance isForeignOptions :: IsForeign Options where
-  read obj = Options <$> ({ noPrelude: _
-                          , noOpts: _
-                          , noMagicDo: _
-                          , noTco: _
-                          , verboseErrors: _
-                          , comments: _
-                          , output: _
-                          , noPrefix: _
-                          , requirePath: _
-                          , src: _
-                          , ffi: _
-                          } <$> readProp noPreludeOpt obj
-                            <*> readProp noOptsOpt obj
-                            <*> readProp noMagicDoOpt obj
-                            <*> readProp noTcoOpt obj
-                            <*> readProp verboseErrorsOpt obj
-                            <*> readProp commentsOpt obj
-                            <*> readProp outputOpt obj
-                            <*> readProp noPrefixOpt obj
-                            <*> readProp requirePathOpt obj
-                            <*> readProp srcOpt obj
-                            <*> readProp ffiOpt obj)
-
-class LoaderOption a where
-  opt :: String -> NullOrUndefined a -> Array String
-
-instance booleanLoaderOption :: LoaderOption Boolean where
-  opt key val = maybe [] (\a -> if a then ["--" ++ key] else []) (runNullOrUndefined val)
-
-instance stringLoaderOption :: LoaderOption String where
-  opt key val = maybe [] (\a -> ["--" ++ key ++ "=" ++ a]) (runNullOrUndefined val)
-
-instance arrayLoaderOption :: (LoaderOption a) => LoaderOption (Array a) where
-  opt key val = concat (opt key <$> (NullOrUndefined <<< Just)
-                                <$> (fromMaybe [] (runNullOrUndefined val)))
-
-pscOptions :: Foreign -> Array String
-pscOptions query = either (const []) fold parsed
-  where parsed = read query :: F Options
-        fold (Options a) = opt noPreludeOpt a.noPrelude <>
-                           opt noOptsOpt a.noOpts <>
-                           opt noMagicDoOpt a.noMagicDo <>
-                           opt noTcoOpt a.noTco <>
-                           opt verboseErrorsOpt a.verboseErrors <>
-                           opt commentsOpt a.comments <>
-                           opt outputOpt a.output <>
-                           opt noPrefixOpt a.noPrefix <>
-                           opt requirePathOpt a.requirePath <>
-                           opt ffiOpt a.ffi
-
-loaderSrcOption :: Foreign -> Maybe (Array String)
-loaderSrcOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.src) (read query)
-
-loaderFFIOption :: Foreign -> Maybe (Array String)
-loaderFFIOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.ffi) (read query)
+  read obj =
+    Options <$> ({ bundleOutput: _ }
+            <$> (maybe bundleOutputDefault id <<< runNullOrUndefined <$> readProp bundleOutput obj))
+    where
+    bundleOutput :: String
+    bundleOutput = "bundleOutput"
+
+    bundleOutputDefault :: String
+    bundleOutputDefault = joinPath "output" "bundle.js"