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

Commit fbe48f2

Browse files
committed
Merge pull request #47 from purescript-contrib/topic/issue-39
Adding the require-path option for psc
2 parents 9e123f6 + 4417f9d commit fbe48f2

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ Toggles `--main` or sets `--main=<string>` that generates code to run the `main`
9696

9797
Sets `--browser-namespace=<string>` that specifies the namespace that PureScript modules will be exported to when running in the browser.
9898

99+
###### `requirePath` (String)
100+
101+
Sets `--require-path=<string>` that specifies the path prefix to use for `require()` calls in the generated JavaScript.
102+
99103
### `purescript.pscDocs(options)`
100104

101105
Invokes the `psc-docs` command. The following options are supported.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
],
3131
"dependencies": {
3232
"async": "^1.3.0",
33+
"camelcase": "^1.1.0",
3334
"cross-spawn": "^0.4.0",
3435
"glob": "^5.0.5",
3536
"gulp-util": "^3.0.4",

src/Options.purs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,35 @@ srcKey = "src"
2424

2525
noOptsOpt = "no-opts"
2626

27-
noOptsKey = "noOpts"
27+
noOptsKey = camelcase noOptsOpt
2828

2929
noMagicDoOpt = "no-magic-do"
3030

31-
noMagicDoKey = "noMagicDo"
31+
noMagicDoKey = camelcase noMagicDoOpt
3232

3333
noTcoOpt = "no-tco"
3434

3535
noTcoKey = "noTco"
3636

3737
verboseErrorsOpt = "verbose-errors"
3838

39-
verboseErrorsKey = "verboseErrors"
39+
verboseErrorsKey = camelcase verboseErrorsOpt
4040

4141
outputOpt = "output"
4242

4343
outputKey = outputOpt
4444

4545
browserNamespaceOpt = "browser-namespace"
4646

47-
browserNamespaceKey = "browserNamespace"
47+
browserNamespaceKey = camelcase browserNamespaceOpt
4848

4949
commentsOpt = "comments"
5050

5151
commentsKey = commentsOpt
5252

5353
noPrefixOpt = "no-prefix"
5454

55-
noPrefixKey = "noPrefix"
55+
noPrefixKey = camelcase noPrefixOpt
5656

5757
mainOpt = "main"
5858

@@ -74,6 +74,10 @@ docgenOpt = "docgen"
7474

7575
docgenKey = docgenOpt
7676

77+
requirePathOpt = "require-path"
78+
79+
requirePathKey = camelcase requirePathOpt
80+
7781
newtype Psc
7882
= Psc { src :: Either String [String]
7983
, ffi :: NullOrUndefined (Either String [String])
@@ -84,6 +88,7 @@ newtype Psc
8488
, verboseErrors :: NullOrUndefined Boolean
8589
, comments :: NullOrUndefined Boolean
8690
, noPrefix :: NullOrUndefined Boolean
91+
, requirePath :: NullOrUndefined String
8792
}
8893

8994
newtype PscBundle
@@ -126,6 +131,7 @@ instance isForeignPsc :: IsForeign Psc where
126131
, verboseErrors: _
127132
, comments: _
128133
, noPrefix: _
134+
, requirePath: _
129135
} <$> readProp srcKey obj
130136
<*> readProp ffiKey obj
131137
<*> readProp outputKey obj
@@ -134,7 +140,8 @@ instance isForeignPsc :: IsForeign Psc where
134140
<*> readProp noOptsKey obj
135141
<*> readProp verboseErrorsKey obj
136142
<*> readProp commentsKey obj
137-
<*> readProp noPrefixKey obj)
143+
<*> readProp noPrefixKey obj
144+
<*> readProp requirePathKey obj)
138145

139146
instance isForeignPscBundle :: IsForeign PscBundle where
140147
read obj =
@@ -238,7 +245,8 @@ pscOptions opts = fold <$> parsed
238245
opt noOptsOpt a.noOpts <>
239246
opt verboseErrorsOpt a.verboseErrors <>
240247
opt commentsOpt a.comments <>
241-
opt noPrefixOpt a.noPrefix
248+
opt noPrefixOpt a.noPrefix <>
249+
opt requirePathOpt a.requirePath
242250

243251
pscBundleOptions :: Foreign -> Either ForeignError [String]
244252
pscBundleOptions opts = fold <$> parsed
@@ -256,12 +264,12 @@ pscDocsOptions opts = fold <$> parsed
256264
opt formatOpt a.format <>
257265
opt docgenOpt a.docgen
258266

259-
foreign import expandGlob
260-
"""
261-
var expandGlob = (function () {
262-
var glob = require("glob");
263-
return function (pattern) {
264-
return glob.sync(pattern);
265-
};
266-
}());
267-
""" :: String -> [String]
267+
foreign import expandGlob """
268+
function expandGlob() {
269+
var glob = require("glob");
270+
return function(pattern) {
271+
return glob.sync(pattern);
272+
};
273+
}""" :: String -> [String]
274+
275+
foreign import camelcase "function camelcase(a){return require('camelcase')(a);}" :: String -> String

0 commit comments

Comments
 (0)