module Slick.Utils
( getDirectoryPaths
, convert
) where
import Data.Aeson as A
import Development.Shake
import Development.Shake.FilePath
getDirectoryPaths :: [FilePath]
-> [FilePath]
-> Action [FilePath]
getDirectoryPaths :: [FilePath] -> [FilePath] -> Action [FilePath]
getDirectoryPaths [FilePath]
extensions [FilePath]
dirs =
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM FilePath -> Action [FilePath]
getPaths [FilePath]
dirs
where
getPaths :: FilePath -> Action [FilePath]
getPaths :: FilePath -> Action [FilePath]
getPaths FilePath
dir =
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (FilePath
dir FilePath -> FilePath -> FilePath
</>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
FilePath -> [FilePath] -> Action [FilePath]
getDirectoryFiles FilePath
dir [FilePath]
extensions
convert :: (FromJSON a, ToJSON a, FromJSON b) => a -> Action b
convert :: forall a b. (FromJSON a, ToJSON a, FromJSON b) => a -> Action b
convert a
a = case forall a. FromJSON a => Value -> Result a
fromJSON (forall a. ToJSON a => a -> Value
toJSON a
a) of
A.Success b
r -> forall (f :: * -> *) a. Applicative f => a -> f a
pure b
r
A.Error FilePath
err -> forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail forall a b. (a -> b) -> a -> b
$ FilePath
"json conversion error:" forall a. [a] -> [a] -> [a]
++ FilePath
err