aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/PursLoader/Options.purs
diff options
context:
space:
mode:
authorNathan Faubion <nathan@n-son.com>2015-11-02 14:04:58 -0600
committerNathan Faubion <nathan@n-son.com>2015-11-02 14:16:21 -0600
commit2b620717603a6a2ba4d93ee1ca7334dc31500acf (patch)
tree7548d0a34052169d853ecd5959eb6f1663c129d1 /src/PursLoader/Options.purs
parent8a0ac07ec2c568b8e9bd06cfd0429c6d6aa836e5 (diff)
downloadpurs-loader-2b620717603a6a2ba4d93ee1ca7334dc31500acf.tar.gz
purs-loader-2b620717603a6a2ba4d93ee1ca7334dc31500acf.tar.zst
purs-loader-2b620717603a6a2ba4d93ee1ca7334dc31500acf.zip
Remove `require-path`, use relative paths for PS
Fixes #15 Removes the `require-path` option and fixes it to '../'. When generating the temporary module for Webpack, use a relative path to the output directory so it doesn't need to be in `modulesDirectories`.
Diffstat (limited to 'src/PursLoader/Options.purs')
-rw-r--r--src/PursLoader/Options.purs40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/PursLoader/Options.purs b/src/PursLoader/Options.purs
index e3957eb..1650652 100644
--- a/src/PursLoader/Options.purs
+++ b/src/PursLoader/Options.purs
@@ -2,9 +2,11 @@ module PursLoader.Options
2 ( pscOptions 2 ( pscOptions
3 , loaderSrcOption 3 , loaderSrcOption
4 , loaderFFIOption 4 , loaderFFIOption
5 , Options()
6 , output
5 ) where 7 ) where
6 8
7import Prelude (Unit(), (<>), (<$>), (<<<), (++), (<*>), const) 9import Prelude (Unit(), (<>), (<$>), (<<<), (++), (<*>), ($), const, id)
8 10
9import Data.Array (concat) 11import Data.Array (concat)
10import Data.Either (either) 12import Data.Either (either)
@@ -44,13 +46,16 @@ newtype Options
44 , noTco :: NullOrUndefined Boolean 46 , noTco :: NullOrUndefined Boolean
45 , verboseErrors :: NullOrUndefined Boolean 47 , verboseErrors :: NullOrUndefined Boolean
46 , comments :: NullOrUndefined Boolean 48 , comments :: NullOrUndefined Boolean
47 , output :: NullOrUndefined String 49 , output :: String
48 , noPrefix :: NullOrUndefined Boolean 50 , noPrefix :: NullOrUndefined Boolean
49 , requirePath :: NullOrUndefined String 51 , requirePath :: String
50 , src :: NullOrUndefined (Array String) 52 , src :: NullOrUndefined (Array String)
51 , ffi :: NullOrUndefined (Array String) 53 , ffi :: NullOrUndefined (Array String)
52 } 54 }
53 55
56output :: Options -> String
57output (Options o) = o.output
58
54instance isForeignOptions :: IsForeign Options where 59instance isForeignOptions :: IsForeign Options where
55 read obj = Options <$> ({ noPrelude: _ 60 read obj = Options <$> ({ noPrelude: _
56 , noOpts: _ 61 , noOpts: _
@@ -60,7 +65,7 @@ instance isForeignOptions :: IsForeign Options where
60 , comments: _ 65 , comments: _
61 , output: _ 66 , output: _
62 , noPrefix: _ 67 , noPrefix: _
63 , requirePath: _ 68 , requirePath: "../"
64 , src: _ 69 , src: _
65 , ffi: _ 70 , ffi: _
66 } <$> readProp noPreludeOpt obj 71 } <$> readProp noPreludeOpt obj
@@ -69,9 +74,8 @@ instance isForeignOptions :: IsForeign Options where
69 <*> readProp noTcoOpt obj 74 <*> readProp noTcoOpt obj
70 <*> readProp verboseErrorsOpt obj 75 <*> readProp verboseErrorsOpt obj
71 <*> readProp commentsOpt obj 76 <*> readProp commentsOpt obj
72 <*> readProp outputOpt obj 77 <*> (maybe "output" id <<< runNullOrUndefined <$> readProp outputOpt obj)
73 <*> readProp noPrefixOpt obj 78 <*> readProp noPrefixOpt obj
74 <*> readProp requirePathOpt obj
75 <*> readProp srcOpt obj 79 <*> readProp srcOpt obj
76 <*> readProp ffiOpt obj) 80 <*> readProp ffiOpt obj)
77 81
@@ -88,19 +92,17 @@ instance arrayLoaderOption :: (LoaderOption a) => LoaderOption (Array a) where
88 opt key val = concat (opt key <$> (NullOrUndefined <<< Just) 92 opt key val = concat (opt key <$> (NullOrUndefined <<< Just)
89 <$> (fromMaybe [] (runNullOrUndefined val))) 93 <$> (fromMaybe [] (runNullOrUndefined val)))
90 94
91pscOptions :: Foreign -> Array String 95pscOptions :: Options -> Array String
92pscOptions query = either (const []) fold parsed 96pscOptions (Options a) = opt noPreludeOpt a.noPrelude <>
93 where parsed = read query :: F Options 97 opt noOptsOpt a.noOpts <>
94 fold (Options a) = opt noPreludeOpt a.noPrelude <> 98 opt noMagicDoOpt a.noMagicDo <>
95 opt noOptsOpt a.noOpts <> 99 opt noTcoOpt a.noTco <>
96 opt noMagicDoOpt a.noMagicDo <> 100 opt verboseErrorsOpt a.verboseErrors <>
97 opt noTcoOpt a.noTco <> 101 opt commentsOpt a.comments <>
98 opt verboseErrorsOpt a.verboseErrors <> 102 opt outputOpt (NullOrUndefined $ Just a.output) <>
99 opt commentsOpt a.comments <> 103 opt noPrefixOpt a.noPrefix <>
100 opt outputOpt a.output <> 104 opt requirePathOpt (NullOrUndefined $ Just a.requirePath) <>
101 opt noPrefixOpt a.noPrefix <> 105 opt ffiOpt a.ffi
102 opt requirePathOpt a.requirePath <>
103 opt ffiOpt a.ffi
104 106
105loaderSrcOption :: Foreign -> Maybe (Array String) 107loaderSrcOption :: Foreign -> Maybe (Array String)
106loaderSrcOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.src) (read query) 108loaderSrcOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.src) (read query)