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

Migrate to namespace option #54

Merged
merged 1 commit into from
Sep 9, 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ The name of the module or modules to use as entry points for dead code eliminati

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

###### `browserNamespace` (String)
###### `namespace` (String)

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

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

Expand Down
4 changes: 2 additions & 2 deletions 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.11.3",
"purescript-foreign": "~0.6.0"
"purescript-aff": "~0.12.0",
"purescript-foreign": "~0.7.0"
}
}
39 changes: 21 additions & 18 deletions src/GulpPurescript/Options.purs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ outputOpt = "output"

outputKey = outputOpt

browserNamespaceOpt = "browser-namespace"
namespaceOpt = "namespace"

browserNamespaceKey = camelcaseFn browserNamespaceOpt
namespaceKey = namespaceOpt

commentsOpt = "comments"

Expand Down Expand Up @@ -98,7 +98,7 @@ newtype PscBundle
, output :: NullOrUndefined String
, "module" :: NullOrUndefined (Either String (Array String))
, main :: NullOrUndefined (Either Boolean String)
, browserNamespace :: NullOrUndefined String
, namespace :: NullOrUndefined String
}

newtype PscDocs
Expand All @@ -118,10 +118,6 @@ newtype PathArray = PathArray (Array String)

data Format = Markdown | ETags | CTags

instance isForeignEither :: (IsForeign a, IsForeign b) => IsForeign (Either a b) where
read a = (Left <$> read a :: F a) <|>
(Right <$> read a :: F b)

instance isForeignPsc :: IsForeign Psc where
read obj =
Psc <$> ({ src: _
Expand All @@ -134,8 +130,8 @@ instance isForeignPsc :: IsForeign Psc where
, comments: _
, noPrefix: _
, requirePath: _
} <$> readProp srcKey obj
<*> readProp ffiKey obj
} <$> (readProp srcKey obj >>= readEither)
<*> (readProp ffiKey obj >>= readEitherNU)
<*> readProp outputKey obj
<*> readProp noTcoKey obj
<*> readProp noMagicDoKey obj
Expand All @@ -151,28 +147,28 @@ instance isForeignPscBundle :: IsForeign PscBundle where
, output: _
, "module": _
, main: _
, browserNamespace: _
} <$> readProp srcKey obj
, namespace: _
} <$> (readProp srcKey obj >>= readEither)
<*> readProp outputKey obj
<*> readProp moduleKey obj
<*> readProp mainKey obj
<*> readProp browserNamespaceKey obj)
<*> (readProp moduleKey obj >>= readEitherNU)
<*> (readProp mainKey obj >>= readEitherNU)
<*> readProp namespaceKey obj)

instance isForeignPscDocs :: IsForeign PscDocs where
read obj =
PscDocs <$> ({ src: _
, format: _
, docgen: _
} <$> readProp srcKey obj
} <$> (readProp srcKey obj >>= readEither)
<*> readProp formatKey obj
<*> readProp docgenOpt obj)

instance isForeignPsci :: IsForeign Psci where
read obj =
Psci <$> ({ src: _
, ffi: _
} <$> readProp srcKey obj
<*> readProp ffiKey obj)
} <$> (readProp srcKey obj >>= readEither)
<*> (readProp ffiKey obj >>= readEitherNU))

instance isForeignPathArray :: IsForeign PathArray where
read val = PathArray <$> read val
Expand Down Expand Up @@ -257,7 +253,7 @@ pscBundleOptions opts = fold <$> parsed
opt outputOpt a.output <>
opt moduleOpt a."module" <>
opt mainOpt a.main <>
opt browserNamespaceOpt a.browserNamespace
opt namespaceOpt a.namespace

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

readEither :: forall left right. (IsForeign left, IsForeign right) => Foreign -> F (Either left right)
readEither a = (Left <$> read a) <|> (Right <$> read a)

readEitherNU :: forall left right. (IsForeign left, IsForeign right) => NullOrUndefined Foreign -> F (NullOrUndefined (Either left right))
readEitherNU a @ (NullOrUndefined Nothing) = pure (NullOrUndefined Nothing)
readEitherNU (NullOrUndefined (Just a)) = (NullOrUndefined <<< Just) <$> readEither a

foreign import expandGlob :: String -> (Array String)

foreign import camelcaseFn :: String -> String
2 changes: 1 addition & 1 deletion src/GulpPurescript/Plugin.purs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pscDocsCommand = "psc-docs"

foreign import cwd :: String

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

Expand Down