Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Add RTS options reading from argv #57

Merged
merged 4 commits into from
Nov 28, 2015
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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ There is also [a more complete example](#full-example) that makes use of all the

Refer to the PureScript [compiler usage](https://github.com/purescript/purescript/wiki/Language-Guide:-Getting-Started#compiler-usage) section of the Github wiki for additional details on the behaviour of each option below.

Options can be passed to the Haskell runtime system for `psc` by passing a `--psc-rts-opts` argument to `gulp`. Any values that follow this flag will be passed through to the runtime. There is no need to include `+RTS`/`-RTS` options as these are inserted automatically. See [the GHC documentation](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/runtime-control.html#rts-opts-cmdline) for information on the available RTS options.

### `purescript.psc(options)`

Invokes the `psc` command. The following options are supported.
Expand Down Expand Up @@ -74,6 +76,10 @@ Sets `--output=<string>` the specifies the output directory, `output` by default

Toggles `--no-prefix` that does not include the comment header.

###### `requirePath` (String)

Sets `--require-path=<string>` that specifies the path prefix to use for `require()` calls in the generated JavaScript.

### `purescript.pscBundle(options)`

Invokes the `psc-bundle` command. The following options are supported.
Expand All @@ -100,7 +106,7 @@ Sets `--namespace=<string>` that specifies the namespace that PureScript modules

###### `requirePath` (String)

Sets `--require-path=<string>` that specifies the path prefix to use for `require()` calls in the generated JavaScript.
Sets `--require-path=<string>` that specifies the path prefix to use for `require()` calls in the generated JavaScript. This should be set any value used in the `psc` task.

### `purescript.pscDocs(options)`

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "gulp-purescript",
"private": true,
"devDependencies": {
"purescript-aff": "~0.12.0",
"purescript-aff": "~0.13.0",
"purescript-foreign": "~0.7.0"
}
}
8 changes: 6 additions & 2 deletions src/GulpPurescript/Options.purs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ newtype PscBundle
, "module" :: NullOrUndefined (Either String (Array String))
, main :: NullOrUndefined (Either Boolean String)
, namespace :: NullOrUndefined String
, requirePath :: NullOrUndefined String
}

newtype PscDocs
Expand Down Expand Up @@ -148,11 +149,13 @@ instance isForeignPscBundle :: IsForeign PscBundle where
, "module": _
, main: _
, namespace: _
, requirePath: _
} <$> (readProp srcKey obj >>= readEither)
<*> readProp outputKey obj
<*> (readProp moduleKey obj >>= readEitherNU)
<*> (readProp mainKey obj >>= readEitherNU)
<*> readProp namespaceKey obj)
<*> readProp namespaceKey obj
<*> readProp requirePathKey obj)

instance isForeignPscDocs :: IsForeign PscDocs where
read obj =
Expand Down Expand Up @@ -253,7 +256,8 @@ pscBundleOptions opts = fold <$> parsed
opt outputOpt a.output <>
opt moduleOpt a."module" <>
opt mainOpt a.main <>
opt namespaceOpt a.namespace
opt namespaceOpt a.namespace <>
opt requirePathOpt a.requirePath

pscDocsOptions :: Foreign -> Either ForeignError (Array String)
pscDocsOptions opts = fold <$> parsed
Expand Down
1 change: 1 addition & 0 deletions src/GulpPurescript/Plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
var cwd = process.cwd();

exports.cwd = cwd;
exports.argv = process.argv;
29 changes: 23 additions & 6 deletions src/GulpPurescript/Plugin.purs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ import Control.Monad.Eff.Class (liftEff)
import Control.Monad.Eff.Exception (Error())
import Control.Monad.Error.Class (catchError, throwError)

import Data.Array (concat)
import Data.Array as A
import Data.Either (Either(..), either)
import Data.Foreign (Foreign())
import Data.Foreign.Class (IsForeign, read, readProp)
import Data.Foreign.Class (read)
import Data.Foreign.NullOrUndefined (runNullOrUndefined)
import Data.Maybe (Maybe(Just), maybe, fromMaybe)
import Data.Maybe (Maybe(..), maybe, fromMaybe)
import Data.String (joinWith, null)
import Data.Tuple (Tuple(..))
import Data.Tuple.Nested (tuple2)

import GulpPurescript.Buffer (Buffer(), mkBufferFromString)
import GulpPurescript.Buffer (mkBufferFromString)
import GulpPurescript.ChildProcess (ChildProcess(), spawn)
import GulpPurescript.Glob (Glob(), globAll)
import GulpPurescript.GulpUtil (File(), mkFile, mkPluginError)
Expand All @@ -39,6 +39,15 @@ import GulpPurescript.ResolveBin (ResolveBin(), resolveBin)
import GulpPurescript.Stream (Stream(), ReadableStream(), mkReadableStreamFromAff)
import GulpPurescript.Which (Which(), which)

foreign import argv :: Array String

rtsOpts :: Array String
rtsOpts =
let startIndex = A.elemIndex "--psc-rts-flags" argv
in case startIndex of
Just i -> ["+RTS"] <> A.drop (i + 1) argv <> ["-RTS"]
_ -> []

type Effects eff =
( cp :: ChildProcess
, glob :: Glob
Expand All @@ -55,20 +64,28 @@ type Errorback eff = Error -> Eff (Effects eff) Unit

type Callback eff a = a -> Eff (Effects eff) Unit

nodeCommand :: String
nodeCommand = "node"

pursPackage :: String
pursPackage = "purescript"

psciFilename :: String
psciFilename = ".psci"

psciLoadModuleCommand :: String
psciLoadModuleCommand = ":m"

psciLoadForeignCommand :: String
psciLoadForeignCommand = ":f"

pscCommand :: String
pscCommand = "psc"

pscBundleCommand :: String
pscBundleCommand = "psc-bundle"

pscDocsCommand :: String
pscDocsCommand = "psc-docs"

foreign import cwd :: String
Expand Down Expand Up @@ -103,7 +120,7 @@ execute cmd args = do
psc :: forall eff. Foreign -> Eff (Effects eff) (ReadableStream Unit)
psc opts = mkReadableStreamFromAff $ do
output <- either (throwPluginError <<< show)
(execute pscCommand)
(execute pscCommand <<< (<> rtsOpts))
(pscOptions opts)
if null output
then pure unit
Expand Down Expand Up @@ -131,7 +148,7 @@ psci opts = mkReadableStreamFromAff (either (throwPluginError <<< show) run (rea
srcs <- globAll (either pure id a.src)
ffis <- globAll (either pure id (fromMaybe (Right []) (runNullOrUndefined a.ffi)))

let lines = (loadModule <$> concat srcs) <> (loadForeign <$> concat ffis)
let lines = (loadModule <$> A.concat srcs) <> (loadForeign <$> A.concat ffis)
buffer = mkBufferFromString (joinWith "\n" lines)

return (mkFile psciFilename buffer)
Expand Down