From 3127d4b0c9309e638ef6627152f9d04bcc7cdf7b Mon Sep 17 00:00:00 2001 From: eric thul Date: Tue, 8 Sep 2015 21:48:27 -0400 Subject: [PATCH] Migrate to namespace option Resolves #53 --- README.md | 4 ++-- bower.json | 4 ++-- src/GulpPurescript/Options.purs | 39 ++++++++++++++++++--------------- src/GulpPurescript/Plugin.purs | 2 +- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index cfc4829..620b259 100644 --- a/README.md +++ b/README.md @@ -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=` 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=` that specifies the namespace that PureScript modules will be exported to when running in the browser. +Sets `--namespace=` that specifies the namespace that PureScript modules will be exported to when running in the browser. ###### `requirePath` (String) diff --git a/bower.json b/bower.json index 9acbabd..11ab059 100644 --- a/bower.json +++ b/bower.json @@ -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" } } diff --git a/src/GulpPurescript/Options.purs b/src/GulpPurescript/Options.purs index 1929514..763ac9c 100644 --- a/src/GulpPurescript/Options.purs +++ b/src/GulpPurescript/Options.purs @@ -44,9 +44,9 @@ outputOpt = "output" outputKey = outputOpt -browserNamespaceOpt = "browser-namespace" +namespaceOpt = "namespace" -browserNamespaceKey = camelcaseFn browserNamespaceOpt +namespaceKey = namespaceOpt commentsOpt = "comments" @@ -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 @@ -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: _ @@ -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 @@ -151,19 +147,19 @@ 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) @@ -171,8 +167,8 @@ 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 @@ -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 @@ -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 diff --git a/src/GulpPurescript/Plugin.purs b/src/GulpPurescript/Plugin.purs index ff5581b..0b559dd 100644 --- a/src/GulpPurescript/Plugin.purs +++ b/src/GulpPurescript/Plugin.purs @@ -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