@@ -5,8 +5,11 @@
6module Language.PureScript.Publish
6module Language.PureScript.Publish
7 ( preparePackage
7 ( preparePackage
8 , PrepareM()
9 , PrepareM()
9 , runPrepareM
10 , runPrepareM
12+ , defaultPublishOptions
10 , getVersionFromGitTag
13 , getVersionFromGitTag
11 , getBowerInfo
14 , getBowerInfo
12 , getModulesAndBookmarks
15 , getModulesAndBookmarks
@@ -49,11 +52,22 @@ import qualified Language.PureScript.Docs as D
49import Language.PureScript.Publish.Utils
52import Language.PureScript.Publish.Utils
50import Language.PureScript.Publish.ErrorsWarnings
53import Language.PureScript.Publish.ErrorsWarnings
55+data PublishOptions = PublishOptions
56+ { -- | How to obtain the version tag and version that the data being
57+ -- generated will refer to.
58+ publishGetVersion :: PrepareM (String, Version)
61+defaultPublishOptions :: PublishOptions
62+defaultPublishOptions = PublishOptions
63+ { publishGetVersion = getVersionFromGitTag
52-- | Attempt to retrieve package metadata from the current directory.
66-- | Attempt to retrieve package metadata from the current directory.
53-- Calls exitFailure if no package metadata could be retrieved.
67-- Calls exitFailure if no package metadata could be retrieved.
54−preparePackage :: IO D.UploadedPackage
68+preparePackage :: PublishOptions -> IO D.UploadedPackage
55−preparePackage =
69+preparePackage opts =
56− runPrepareM preparePackage'
70+ runPrepareM (preparePackage' opts)
57 >>= either (\e -> printError e >> exitFailure)
71 >>= either (\e -> printError e >> exitFailure)
58 handleWarnings
72 handleWarnings
@@ -93,14 +107,14 @@ otherError = throwError . OtherError
93catchLeft :: Applicative f => Either a b -> (a -> f b) -> f b
107catchLeft :: Applicative f => Either a b -> (a -> f b) -> f b
94catchLeft a f = either f pure a
108catchLeft a f = either f pure a
96−preparePackage' :: PrepareM D.UploadedPackage
110+preparePackage' :: PublishOptions -> PrepareM D.UploadedPackage
97−preparePackage' = do
111+preparePackage' opts = do
98 exists <- liftIO (doesFileExist "bower.json")
112 exists <- liftIO (doesFileExist "bower.json")
99 unless exists (userError BowerJSONNotFound)
113 unless exists (userError BowerJSONNotFound)
101 pkgMeta <- liftIO (Bower.decodeFile "bower.json")
115 pkgMeta <- liftIO (Bower.decodeFile "bower.json")
102 >>= flip catchLeft (userError . CouldntParseBowerJSON)
116 >>= flip catchLeft (userError . CouldntParseBowerJSON)
103− (pkgVersionTag, pkgVersion) <- getVersionFromGitTag
117+ (pkgVersionTag, pkgVersion) <- publishGetVersion opts
104 pkgGithub <- getBowerInfo pkgMeta
118 pkgGithub <- getBowerInfo pkgMeta
105 (pkgBookmarks, pkgModules) <- getModulesAndBookmarks
119 (pkgBookmarks, pkgModules) <- getModulesAndBookmarks