Add dependencies field to Deps
This commit is contained in:
parent
3c1b9f7171
commit
8a46ead147
2 changed files with 33 additions and 15 deletions
|
@ -110,7 +110,8 @@ Library
|
||||||
text,
|
text,
|
||||||
transformers >= 0.2,
|
transformers >= 0.2,
|
||||||
union-find,
|
union-find,
|
||||||
uniplate
|
uniplate,
|
||||||
|
unordered-containers
|
||||||
|
|
||||||
Executable elm
|
Executable elm
|
||||||
Main-is: Compiler.hs
|
Main-is: Compiler.hs
|
||||||
|
@ -189,7 +190,8 @@ Executable elm
|
||||||
text,
|
text,
|
||||||
transformers >= 0.2,
|
transformers >= 0.2,
|
||||||
union-find,
|
union-find,
|
||||||
uniplate
|
uniplate,
|
||||||
|
unordered-containers
|
||||||
|
|
||||||
Executable elm-doc
|
Executable elm-doc
|
||||||
Main-is: Docs.hs
|
Main-is: Docs.hs
|
||||||
|
|
|
@ -7,7 +7,7 @@ import qualified Control.Exception as E
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import qualified Data.List as List
|
import qualified Data.List as List
|
||||||
import qualified Data.ByteString.Lazy as BS
|
import qualified Data.ByteString.Lazy as BS
|
||||||
import qualified Data.Map as Map
|
import qualified Data.HashMap.Strict as Map
|
||||||
import qualified Elm.Internal.Name as N
|
import qualified Elm.Internal.Name as N
|
||||||
import qualified Elm.Internal.Version as V
|
import qualified Elm.Internal.Version as V
|
||||||
|
|
||||||
|
@ -20,35 +20,54 @@ data Deps = Deps
|
||||||
, repo :: String
|
, repo :: String
|
||||||
, exposed :: [String]
|
, exposed :: [String]
|
||||||
, elmVersion :: V.Version
|
, elmVersion :: V.Version
|
||||||
|
, dependencies :: [(N.Name,V.Version)]
|
||||||
} deriving Show
|
} deriving Show
|
||||||
|
|
||||||
instance FromJSON Deps where
|
instance FromJSON Deps where
|
||||||
parseJSON (Object obj) =
|
parseJSON (Object obj) =
|
||||||
do version <- obj .: "version"
|
do version <- get obj "version" "your projects version number"
|
||||||
|
|
||||||
summary <- obj .: "summary"
|
summary <- get obj "summary" "a short summary of your project"
|
||||||
when (length summary >= 80) $
|
when (length summary >= 80) $
|
||||||
fail "'summary' must be less than 80 characters"
|
fail "'summary' must be less than 80 characters"
|
||||||
|
|
||||||
desc <- obj .: "description"
|
desc <- get obj "description" "an extended description of your project \
|
||||||
license <- obj .: "license"
|
\and how to get started with it."
|
||||||
|
license <- get obj "license" "license information (BSD3 is recommended)"
|
||||||
|
|
||||||
repo <- obj .: "repository"
|
repo <- get obj "repository" "a link to the project's GitHub repo"
|
||||||
name <- case repoToName repo of
|
name <- case repoToName repo of
|
||||||
Left err -> fail err
|
Left err -> fail err
|
||||||
Right nm -> return nm
|
Right nm -> return nm
|
||||||
|
|
||||||
exposed <- obj .: "exposed-modules"
|
exposed <- get obj "exposed-modules" "a list of modules exposed to users"
|
||||||
when (null exposed) $
|
when (null exposed) $
|
||||||
fail "there are no 'exposed-modules'.\n\
|
fail "there are no 'exposed-modules'.\n\
|
||||||
\At least one module must be exposed for anyone to use this library!"
|
\At least one module must be exposed \
|
||||||
|
\for anyone to use this library!"
|
||||||
|
|
||||||
elmVersion <- obj .: "elm-version"
|
elmVersion <- get obj "elm-version" "the version of the Elm compiler you are using"
|
||||||
|
|
||||||
return $ Deps name version summary desc license repo exposed elmVersion
|
deps <- toDeps =<< get obj "dependencies"
|
||||||
|
"a listing of your project's dependencies"
|
||||||
|
|
||||||
|
return $ Deps name version summary desc license repo exposed elmVersion deps
|
||||||
|
|
||||||
parseJSON _ = mzero
|
parseJSON _ = mzero
|
||||||
|
|
||||||
|
toDeps deps =
|
||||||
|
forM (Map.toList deps) $ \(f,v) ->
|
||||||
|
case (N.fromString f, V.fromString v) of
|
||||||
|
(Just name, Just version) -> return (name,version)
|
||||||
|
(Nothing, _) -> fail $ N.errorMsg f
|
||||||
|
(_, Nothing) -> fail $ "invalid version number " ++ v
|
||||||
|
|
||||||
|
get obj field desc =
|
||||||
|
do maybe <- obj .:? field
|
||||||
|
case maybe of
|
||||||
|
Nothing -> fail $ "Missing field " ++ show field ++ ", " ++ desc
|
||||||
|
Just value -> return value
|
||||||
|
|
||||||
repoToName :: String -> Either String N.Name
|
repoToName :: String -> Either String N.Name
|
||||||
repoToName repo
|
repoToName repo
|
||||||
| not (end `List.isSuffixOf` repo) = Left msg
|
| not (end `List.isSuffixOf` repo) = Left msg
|
||||||
|
@ -86,8 +105,5 @@ withDeps handle path =
|
||||||
"could not find file " ++ path ++
|
"could not find file " ++ path ++
|
||||||
"\n You may need to create a dependency file for your project."
|
"\n You may need to create a dependency file for your project."
|
||||||
|
|
||||||
dependencies :: FilePath -> ErrorT String IO (Map.Map String String)
|
|
||||||
dependencies _ = return Map.empty -- withDeps deps
|
|
||||||
|
|
||||||
depsAt :: FilePath -> ErrorT String IO Deps
|
depsAt :: FilePath -> ErrorT String IO Deps
|
||||||
depsAt = withDeps id
|
depsAt = withDeps id
|
Loading…
Reference in a new issue