git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
psc-publish: Try "bower.cmd" if "bower" is not found

Fixes #1317

commita8556ff5453f5d9df43deaadc2697e0900add07e authorHarry Garrood <harry@garrood.me> dateSat 1 Aug 2015, 16:49 (11 years ago) parent464af8e
2 files changed+17−2
src/Language/PureScript/Publish.hs+11−2 src/Language/PureScript/Publish/ErrorsWarnings.hs+6
src/Language/PureScript/Publish.hs+11−2
@@ -36,11 +36,12 @@ import Control.Applicative
3636import Control.Category ((>>>))
3737import Control.Arrow ((***))
3838import Control.Exception (catch, try)
39+import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
3940import Control.Monad.Trans.Except
4041import Control.Monad.Error.Class (MonadError(..))
4142import Control.Monad.Writer
4243
43−import System.Directory (doesFileExist)
44+import System.Directory (doesFileExist, findExecutable)
4445import System.Process (readProcess)
4546import System.Exit (exitFailure)
4647import qualified System.FilePath.Glob as Glob
@@ -238,7 +239,8 @@ data DependencyStatus
238239-- appropriate to link to, and we should omit links.
239240getResolvedDependencies :: [PackageName] -> PrepareM [(PackageName, Version)]
240241getResolvedDependencies declaredDeps = do
241− depsBS <- fromString <$> readProcess' "bower" ["list", "--json", "--offline"] ""
242+ bower <- findBowerExecutable
243+ depsBS <- fromString <$> readProcess' bower ["list", "--json", "--offline"] ""
242244
243245 -- Check for undeclared dependencies
244246 toplevels <- catchJSON (parse asToplevelDependencies depsBS)
@@ -250,6 +252,13 @@ getResolvedDependencies declaredDeps = do
250252 where
251253 catchJSON = flip catchLeft (internalError . JSONError FromBowerList)
252254
255+findBowerExecutable :: PrepareM String
256+findBowerExecutable = do
257+ mname <- liftIO . runMaybeT . msum . map (MaybeT . findExecutable) $ names
258+ maybe (userError BowerExecutableNotFound) return mname
259+ where
260+ names = ["bower", "bower.cmd"]
261+
253262-- | Extracts all dependencies and their versions from
254263-- `bower list --json --offline`
255264asResolvedDependencies :: Parse BowerError [(PackageName, DependencyStatus)]
src/Language/PureScript/Publish/ErrorsWarnings.hs+6
@@ -53,6 +53,7 @@ data PackageWarning
5353-- | An error that should be fixed by the user.
5454data UserError
5555 = BowerJSONNotFound
56+ | BowerExecutableNotFound
5657 | CouldntParseBowerJSON (ParseError BowerError)
5758 | BowerJSONNameMissing
5859 | TagMustBeCheckedOut
@@ -121,6 +122,11 @@ displayUserError e = case e of
121122 [ "The bower.json file was not found. Please create one, or run "
122123 , "`pulp init`."
123124 ])
125+ BowerExecutableNotFound ->
126+ para (concat
127+ [ "The \"bower\" executable was not found (nor \"bower.cmd\"). Please"
128+ , " ensure that bower is installed and on your PATH."
129+ ])
124130 CouldntParseBowerJSON err ->
125131 vcat
126132 [ successivelyIndented