]> git.immae.eu Git - github/fretlink/purs-loader.git/commitdiff
Additional loader options
authoreric thul <thul.eric@gmail.com>
Fri, 15 May 2015 02:13:59 +0000 (22:13 -0400)
committereric thul <thul.eric@gmail.com>
Fri, 15 May 2015 02:13:59 +0000 (22:13 -0400)
Adds the `psc-make` options `comments` and `no-prefix`. Also, an
internal option `src` has been added that is used to specify the source
paths of `PureScript` files that will be globbed for compilation.

By default the `bower_components` path is globbed, but the loader
requires that the source paths be provided for the user's code.

Resolves #12

MODULE.md
README.md
example/webpack.config.js
src/Loader.purs
src/Options.purs

index 39d9d3aaa31b9f5c372ace9e88e12509417bf019..2d54719bffc0a018e50338c6c771bb01704c97ef 100644 (file)
--- a/MODULE.md
+++ b/MODULE.md
@@ -177,6 +177,20 @@ instance isForeignOptions :: IsForeign Options
 ```
 
 
+#### `booleanLoaderOption`
+
+``` purescript
+instance booleanLoaderOption :: LoaderOption Boolean
+```
+
+
+#### `stringLoaderOption`
+
+``` purescript
+instance stringLoaderOption :: LoaderOption String
+```
+
+
 #### `pscMakeOutputOption`
 
 ``` purescript
@@ -191,6 +205,13 @@ pscMakeOptions :: Foreign -> [String]
 ```
 
 
+#### `loaderSrcOption`
+
+``` purescript
+loaderSrcOption :: Foreign -> Maybe [String]
+```
+
+
 
 ## Module PursLoader.Path
 
index ee964484df6561d94f07e8eaa07d1292843b9838..d243381aa0b11dbe5131d78433920299f242bb76 100644 (file)
--- a/README.md
+++ b/README.md
@@ -12,18 +12,41 @@ npm install purs-loader --save-dev
 
 ## Options
 
- - **no-prelude**: Boolean value that toggles `--no-prelude`
-  - Do not include the Prelude in the generated Javascript.
- - **no-opts**: Boolean value that toggles `--no-opts`
-  - Disable all optimizations.
- - **no-magic-do**: Boolean value that toggles `--no-magic-do`
-  - Turn off optimizations which inline calls to >>= for the Eff monad.
- - **no-tco**: Boolean value that toggles `--no-tco`
-  - Turn off tail-call elimination.
- - **verbose-errors**: Boolean value that toggles `--verbose-errors`
-  - Generate verbose error messages.
- - **output**: String value that sets `--output=<string>`
-  - Write the generated Javascript to the specified file.
+###### `noPrelude` (Boolean)
+
+Toggles `--no-prelude` that omits the Prelude.
+
+###### `noTco` (Boolean)
+
+Toggles `--no-tco` that disables tail-call optimizations.
+
+###### `noMagicDo` (Boolean)
+
+Toggles `--no-magic-do` that disables optimizations overloading the do keyword generating efficient code for the `Eff` monad.
+
+###### `noOpts` (Boolean)
+
+Toggles `--no-opts` that skips the optimization phase.
+
+###### `verboseErrors` (Boolean)
+
+Toggles `--verbose-errors` that displays verbose error messages.
+
+###### `comments` (Boolean)
+
+Toggles `--comments` that includes comments in generated code.
+
+###### `output` (String)
+
+Sets `--output=<string>` the specifies the output directory, `output` by default.
+
+###### `noPrefix` (Boolean)
+
+Toggles `--no-prefix` that does not include the comment header.
+
+###### `src` (String Array)
+
+Specifies PureScript source paths to be globbed for `.purs` files. By default, `bower_components` is search. Additional paths may be specified using this option. This option is specified as `src[]=path`.
 
 ## Example
 
index 19997f37bb92eb3c3888066bb3bf79db45f00bc7..f67e83ac24248fa4e2ffa6340b691b0167b62c2f 100644 (file)
@@ -5,7 +5,7 @@ var config
     , output: { path: __dirname
               , filename: 'bundle.js'
               }
-    , module: { loaders: [ { test: /\.purs$/, loader: 'purs-loader' } ] }
+    , module: { loaders: [ { test: /\.purs$/, loader: 'purs-loader?src[]=src' } ] }
     , resolve: { modulesDirectories: [ 'node_modules',
                                        'output'
                                      ]
index aae51c0b0ca250df1967854515695966f3d7d677..fedc424be73f9503e8b987da7f8262a94dbb50fd 100644 (file)
@@ -26,7 +26,7 @@ import PursLoader.Glob (Glob(), glob)
 import PursLoader.LoaderRef (LoaderRef(), Loader(), async, cacheable, clearDependencies, addDependency, query, resourcePath)
 import PursLoader.LoaderUtil (getRemainingRequest, parseQuery)
 import PursLoader.OS (eol)
-import PursLoader.Options (pscMakeOptions, pscMakeDefaultOutput, pscMakeOutputOption)
+import PursLoader.Options (loaderSrcOption, pscMakeOptions, pscMakeDefaultOutput, pscMakeOutputOption)
 import PursLoader.Path (dirname, join, relative, resolve)
 
 foreign import cwd "var cwd = process.cwd();" :: String
@@ -43,8 +43,8 @@ indexFilename = "index.js"
 
 (!!!) = flip (!!)
 
-pursPattern :: String -> String
-pursPattern root = join [ "{" ++ joinWith "," [ bowerPattern, root ] ++ "}"
+pursPattern :: [String] -> String
+pursPattern srcs = join [ "{" ++ joinWith "," ([ bowerPattern ] <> srcs) ++ "}"
                         , "**"
                         , "*.purs"
                         ]
@@ -86,10 +86,10 @@ loader' ref source = do
   liftEff $ cacheable ref
 
   let request = getRemainingRequest ref
-      root = dirname $ relative cwd request
       parsed = parseQuery $ query ref
+      srcs = loaderSrcOption parsed
       opts = pscMakeOptions parsed
-      pattern = pursPattern root
+      pattern = pursPattern $ fromMaybe [] srcs
       key = match moduleRegex source >>= (!!!) 1
 
   files <- glob pattern
index b96cddc0998a9b9ea718d364fd2cdc47e130bdde..c47bebc3749f79cf0f2953feb8bb7c5f869ba864 100644 (file)
@@ -2,6 +2,7 @@ module PursLoader.Options
   ( pscMakeOptions
   , pscMakeDefaultOutput
   , pscMakeOutputOption
+  , loaderSrcOption
   ) where
 
 import Data.Either (either)
@@ -24,6 +25,12 @@ verboseErrorsOpt = "verbose-errors"
 
 outputOpt = "output"
 
+commentsOpt = "comments"
+
+noPrefixOpt = "no-prefix"
+
+srcOpt = "src"
+
 pscMakeDefaultOutput = "output"
 
 newtype Options
@@ -32,29 +39,42 @@ newtype Options
             , noMagicDo :: NullOrUndefined Boolean
             , noTco :: NullOrUndefined Boolean
             , verboseErrors :: NullOrUndefined Boolean
+            , comments :: NullOrUndefined Boolean
             , output :: NullOrUndefined String
+            , noPrefix :: NullOrUndefined Boolean
+            , src :: NullOrUndefined [String]
             }
 
 instance isForeignOptions :: IsForeign Options where
-  read obj = (\a b c d e f ->
-             Options { noPrelude: a
-                     , noOpts: b
-                     , noMagicDo: c
-                     , noTco: d
-                     , verboseErrors: e
-                     , output: f
-                     }) <$> readProp noPreludeOpt obj
-                        <*> readProp noOptsOpt obj
-                        <*> readProp noMagicDoOpt obj
-                        <*> readProp noTcoOpt obj
-                        <*> readProp verboseErrorsOpt obj
-                        <*> readProp outputOpt obj
-
-booleanOpt :: String -> NullOrUndefined Boolean -> [String]
-booleanOpt key opt = maybe [] (\a -> if a then ["--" ++ key] else []) (runNullOrUndefined opt)
-
-stringOpt :: String -> NullOrUndefined String -> [String]
-stringOpt key opt = maybe [] (\a -> ["--" ++ key ++ "=" ++ a]) (runNullOrUndefined opt)
+  read obj = Options <$> ({ noPrelude: _
+                          , noOpts: _
+                          , noMagicDo: _
+                          , noTco: _
+                          , verboseErrors: _
+                          , comments: _
+                          , output: _
+                          , noPrefix: _
+                          , src: _
+                          } <$> 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 srcOpt obj)
+
+class LoaderOption a where
+  opt :: String -> NullOrUndefined a -> [String]
+
+instance booleanLoaderOption :: LoaderOption Boolean where
+  opt key opt = maybe [] (\a -> if a then ["--" ++ key] else [])
+                         (runNullOrUndefined opt)
+
+instance stringLoaderOption :: LoaderOption String where
+  opt key opt = maybe [] (\a -> ["--" ++ key ++ "=" ++ a])
+                         (runNullOrUndefined opt)
 
 pscMakeOutputOption :: Foreign -> Maybe String
 pscMakeOutputOption query = either (const Nothing)
@@ -64,9 +84,16 @@ pscMakeOutputOption query = either (const Nothing)
 pscMakeOptions :: Foreign -> [String]
 pscMakeOptions query = either (const []) fold parsed
   where parsed = read query :: F Options
-        fold (Options a) = booleanOpt noPreludeOpt a.noPrelude <>
-                           booleanOpt noOptsOpt a.noOpts <>
-                           booleanOpt noMagicDoOpt a.noMagicDo <>
-                           booleanOpt noTcoOpt a.noTco <>
-                           booleanOpt verboseErrorsOpt a.verboseErrors <>
-                           stringOpt outputOpt a.output
+        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
+
+loaderSrcOption :: Foreign -> Maybe [String]
+loaderSrcOption query = either (const Nothing)
+                               (\(Options a) -> runNullOrUndefined a.src)
+                               (read query)