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

Commit 5e89a3f

Browse files
committed
Merge pull request #54 from purescript-contrib/topic/issue-53
Migrate to namespace option
2 parents 232ddbb + 3127d4b commit 5e89a3f

File tree

4 files changed

+26
-23
lines changed

4 files changed

+26
-23
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ The name of the module or modules to use as entry points for dead code eliminati
9494

9595
Toggles `--main` or sets `--main=<string>` that generates code to run the `main` function in the specified module or the `Main` module by default.
9696

97-
###### `browserNamespace` (String)
97+
###### `namespace` (String)
9898

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

101101
###### `requirePath` (String)
102102

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "gulp-purescript",
33
"private": true,
44
"devDependencies": {
5-
"purescript-aff": "~0.11.3",
6-
"purescript-foreign": "~0.6.0"
5+
"purescript-aff": "~0.12.0",
6+
"purescript-foreign": "~0.7.0"
77
}
88
}

src/GulpPurescript/Options.purs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ outputOpt = "output"
4444

4545
outputKey = outputOpt
4646

47-
browserNamespaceOpt = "browser-namespace"
47+
namespaceOpt = "namespace"
4848

49-
browserNamespaceKey = camelcaseFn browserNamespaceOpt
49+
namespaceKey = namespaceOpt
5050

5151
commentsOpt = "comments"
5252

@@ -98,7 +98,7 @@ newtype PscBundle
9898
, output :: NullOrUndefined String
9999
, "module" :: NullOrUndefined (Either String (Array String))
100100
, main :: NullOrUndefined (Either Boolean String)
101-
, browserNamespace :: NullOrUndefined String
101+
, namespace :: NullOrUndefined String
102102
}
103103

104104
newtype PscDocs
@@ -118,10 +118,6 @@ newtype PathArray = PathArray (Array String)
118118

119119
data Format = Markdown | ETags | CTags
120120

121-
instance isForeignEither :: (IsForeign a, IsForeign b) => IsForeign (Either a b) where
122-
read a = (Left <$> read a :: F a) <|>
123-
(Right <$> read a :: F b)
124-
125121
instance isForeignPsc :: IsForeign Psc where
126122
read obj =
127123
Psc <$> ({ src: _
@@ -134,8 +130,8 @@ instance isForeignPsc :: IsForeign Psc where
134130
, comments: _
135131
, noPrefix: _
136132
, requirePath: _
137-
} <$> readProp srcKey obj
138-
<*> readProp ffiKey obj
133+
} <$> (readProp srcKey obj >>= readEither)
134+
<*> (readProp ffiKey obj >>= readEitherNU)
139135
<*> readProp outputKey obj
140136
<*> readProp noTcoKey obj
141137
<*> readProp noMagicDoKey obj
@@ -151,28 +147,28 @@ instance isForeignPscBundle :: IsForeign PscBundle where
151147
, output: _
152148
, "module": _
153149
, main: _
154-
, browserNamespace: _
155-
} <$> readProp srcKey obj
150+
, namespace: _
151+
} <$> (readProp srcKey obj >>= readEither)
156152
<*> readProp outputKey obj
157-
<*> readProp moduleKey obj
158-
<*> readProp mainKey obj
159-
<*> readProp browserNamespaceKey obj)
153+
<*> (readProp moduleKey obj >>= readEitherNU)
154+
<*> (readProp mainKey obj >>= readEitherNU)
155+
<*> readProp namespaceKey obj)
160156

161157
instance isForeignPscDocs :: IsForeign PscDocs where
162158
read obj =
163159
PscDocs <$> ({ src: _
164160
, format: _
165161
, docgen: _
166-
} <$> readProp srcKey obj
162+
} <$> (readProp srcKey obj >>= readEither)
167163
<*> readProp formatKey obj
168164
<*> readProp docgenOpt obj)
169165

170166
instance isForeignPsci :: IsForeign Psci where
171167
read obj =
172168
Psci <$> ({ src: _
173169
, ffi: _
174-
} <$> readProp srcKey obj
175-
<*> readProp ffiKey obj)
170+
} <$> (readProp srcKey obj >>= readEither)
171+
<*> (readProp ffiKey obj >>= readEitherNU))
176172

177173
instance isForeignPathArray :: IsForeign PathArray where
178174
read val = PathArray <$> read val
@@ -257,7 +253,7 @@ pscBundleOptions opts = fold <$> parsed
257253
opt outputOpt a.output <>
258254
opt moduleOpt a."module" <>
259255
opt mainOpt a.main <>
260-
opt browserNamespaceOpt a.browserNamespace
256+
opt namespaceOpt a.namespace
261257

262258
pscDocsOptions :: Foreign -> Either ForeignError (Array String)
263259
pscDocsOptions opts = fold <$> parsed
@@ -266,6 +262,13 @@ pscDocsOptions opts = fold <$> parsed
266262
opt formatOpt a.format <>
267263
opt docgenOpt a.docgen
268264

265+
readEither :: forall left right. (IsForeign left, IsForeign right) => Foreign -> F (Either left right)
266+
readEither a = (Left <$> read a) <|> (Right <$> read a)
267+
268+
readEitherNU :: forall left right. (IsForeign left, IsForeign right) => NullOrUndefined Foreign -> F (NullOrUndefined (Either left right))
269+
readEitherNU a @ (NullOrUndefined Nothing) = pure (NullOrUndefined Nothing)
270+
readEitherNU (NullOrUndefined (Just a)) = (NullOrUndefined <<< Just) <$> readEither a
271+
269272
foreign import expandGlob :: String -> (Array String)
270273

271274
foreign import camelcaseFn :: String -> String

src/GulpPurescript/Plugin.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pscDocsCommand = "psc-docs"
7373

7474
foreign import cwd :: String
7575

76-
throwPluginError :: forall eff. String -> Aff (Effects eff) _
76+
throwPluginError :: forall eff result. String -> Aff (Effects eff) result
7777
throwPluginError msg = liftEff (flip mkPluginError msg <$> (maybe "" (\(Package a) -> a.name))
7878
<$> package) >>= throwError
7979

0 commit comments

Comments
 (0)