]> git.immae.eu Git - github/fretlink/purs-loader.git/blame - src/PursLoader/Options.purs
Update bower deps for latest PS compiler
[github/fretlink/purs-loader.git] / src / PursLoader / Options.purs
CommitLineData
c194f84c 1module PursLoader.Options
1983893b 2 ( pscOptions
a72c8af1 3 , loaderSrcOption
0e1221d7 4 , loaderFFIOption
c194f84c 5 ) where
6
03b840cb 7import Prelude (Unit(), (<>), (<$>), (<<<), (++), (<*>), const)
8
1983893b 9import Data.Array (concat)
c194f84c 10import Data.Either (either)
11
12import Data.Foreign (Foreign(), F())
13import Data.Foreign.Class (IsForeign, read, readProp)
1983893b 14import Data.Foreign.NullOrUndefined (NullOrUndefined(..), runNullOrUndefined)
c194f84c 15
1983893b 16import Data.Maybe (Maybe(..), maybe, fromMaybe)
c194f84c 17
18noPreludeOpt = "no-prelude"
19
20noOptsOpt = "no-opts"
21
22noMagicDoOpt = "no-magic-do"
23
24noTcoOpt = "no-tco"
25
26verboseErrorsOpt = "verbose-errors"
27
28outputOpt = "output"
29
a72c8af1 30commentsOpt = "comments"
31
32noPrefixOpt = "no-prefix"
33
1983893b 34requirePathOpt = "require-path"
35
a72c8af1 36srcOpt = "src"
37
1983893b 38ffiOpt = "ffi"
c194f84c 39
40newtype Options
41 = Options { noPrelude :: NullOrUndefined Boolean
42 , noOpts :: NullOrUndefined Boolean
43 , noMagicDo :: NullOrUndefined Boolean
44 , noTco :: NullOrUndefined Boolean
45 , verboseErrors :: NullOrUndefined Boolean
a72c8af1 46 , comments :: NullOrUndefined Boolean
c194f84c 47 , output :: NullOrUndefined String
a72c8af1 48 , noPrefix :: NullOrUndefined Boolean
1983893b 49 , requirePath :: NullOrUndefined String
03b840cb 50 , src :: NullOrUndefined (Array String)
51 , ffi :: NullOrUndefined (Array String)
c194f84c 52 }
53
54instance isForeignOptions :: IsForeign Options where
a72c8af1 55 read obj = Options <$> ({ noPrelude: _
56 , noOpts: _
57 , noMagicDo: _
58 , noTco: _
59 , verboseErrors: _
60 , comments: _
61 , output: _
62 , noPrefix: _
1983893b 63 , requirePath: _
a72c8af1 64 , src: _
1983893b 65 , ffi: _
a72c8af1 66 } <$> readProp noPreludeOpt obj
67 <*> readProp noOptsOpt obj
68 <*> readProp noMagicDoOpt obj
69 <*> readProp noTcoOpt obj
70 <*> readProp verboseErrorsOpt obj
71 <*> readProp commentsOpt obj
72 <*> readProp outputOpt obj
73 <*> readProp noPrefixOpt obj
1983893b 74 <*> readProp requirePathOpt obj
75 <*> readProp srcOpt obj
76 <*> readProp ffiOpt obj)
a72c8af1 77
78class LoaderOption a where
03b840cb 79 opt :: String -> NullOrUndefined a -> Array String
a72c8af1 80
81instance booleanLoaderOption :: LoaderOption Boolean where
1983893b 82 opt key val = maybe [] (\a -> if a then ["--" ++ key] else []) (runNullOrUndefined val)
a72c8af1 83
84instance stringLoaderOption :: LoaderOption String where
1983893b 85 opt key val = maybe [] (\a -> ["--" ++ key ++ "=" ++ a]) (runNullOrUndefined val)
c194f84c 86
03b840cb 87instance arrayLoaderOption :: (LoaderOption a) => LoaderOption (Array a) where
1983893b 88 opt key val = concat (opt key <$> (NullOrUndefined <<< Just)
89 <$> (fromMaybe [] (runNullOrUndefined val)))
c194f84c 90
03b840cb 91pscOptions :: Foreign -> Array String
1983893b 92pscOptions query = either (const []) fold parsed
c194f84c 93 where parsed = read query :: F Options
a72c8af1 94 fold (Options a) = opt noPreludeOpt a.noPrelude <>
95 opt noOptsOpt a.noOpts <>
96 opt noMagicDoOpt a.noMagicDo <>
97 opt noTcoOpt a.noTco <>
98 opt verboseErrorsOpt a.verboseErrors <>
99 opt commentsOpt a.comments <>
100 opt outputOpt a.output <>
1983893b 101 opt noPrefixOpt a.noPrefix <>
102 opt requirePathOpt a.requirePath <>
103 opt ffiOpt a.ffi
a72c8af1 104
03b840cb 105loaderSrcOption :: Foreign -> Maybe (Array String)
1983893b 106loaderSrcOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.src) (read query)
0e1221d7 107
03b840cb 108loaderFFIOption :: Foreign -> Maybe (Array String)
0e1221d7 109loaderFFIOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.ffi) (read query)