@@ -7,7 +7,7 @@ import qualified Control.Exception as E
7import Data.Aeson
7import Data.Aeson
8import qualified Data.List as List
8import qualified Data.List as List
9import qualified Data.ByteString.Lazy as BS
9import qualified Data.ByteString.Lazy as BS
10−import qualified Data.Map as Map
10+import qualified Data.HashMap.Strict as Map
11import qualified Elm.Internal.Name as N
11import qualified Elm.Internal.Name as N
12import qualified Elm.Internal.Version as V
12import qualified Elm.Internal.Version as V
@@ -20,35 +20,54 @@ data Deps = Deps
20 , repo :: String
20 , repo :: String
21 , exposed :: [String]
21 , exposed :: [String]
22 , elmVersion :: V.Version
22 , elmVersion :: V.Version
23+ , dependencies :: [(N.Name,V.Version)]
23 } deriving Show
24 } deriving Show
25instance FromJSON Deps where
26instance FromJSON Deps where
26 parseJSON (Object obj) =
27 parseJSON (Object obj) =
27− do version <- obj .: "version"
28+ do version <- get obj "version" "your projects version number"
29− summary <- obj .: "summary"
30+ summary <- get obj "summary" "a short summary of your project"
30 when (length summary >= 80) $
31 when (length summary >= 80) $
31 fail "'summary' must be less than 80 characters"
32 fail "'summary' must be less than 80 characters"
33− desc <- obj .: "description"
34+ desc <- get obj "description" "an extended description of your project \
35+ \and how to get started with it."
34− license <- obj .: "license"
36+ license <- get obj "license" "license information (BSD3 is recommended)"
36− repo <- obj .: "repository"
38+ repo <- get obj "repository" "a link to the project's GitHub repo"
37 name <- case repoToName repo of
39 name <- case repoToName repo of
38 Left err -> fail err
40 Left err -> fail err
39 Right nm -> return nm
41 Right nm -> return nm
41− exposed <- obj .: "exposed-modules"
43+ exposed <- get obj "exposed-modules" "a list of modules exposed to users"
42 when (null exposed) $
44 when (null exposed) $
43 fail "there are no 'exposed-modules'.\n\
45 fail "there are no 'exposed-modules'.\n\
44− \At least one module must be exposed for anyone to use this library!"
46+ \At least one module must be exposed \
47+ \for anyone to use this library!"
46− elmVersion <- obj .: "elm-version"
49+ elmVersion <- get obj "elm-version" "the version of the Elm compiler you are using"
51+ deps <- toDeps =<< get obj "dependencies"
52+ "a listing of your project's dependencies"
48− return $ Deps name version summary desc license repo exposed elmVersion
54+ return $ Deps name version summary desc license repo exposed elmVersion deps
50 parseJSON _ = mzero
56 parseJSON _ = mzero
59+ forM (Map.toList deps) $ \(f,v) ->
60+ case (N.fromString f, V.fromString v) of
61+ (Just name, Just version) -> return (name,version)
62+ (Nothing, _) -> fail $ N.errorMsg f
63+ (_, Nothing) -> fail $ "invalid version number " ++ v
66+ do maybe <- obj .:? field
68+ Nothing -> fail $ "Missing field " ++ show field ++ ", " ++ desc
69+ Just value -> return value
52repoToName :: String -> Either String N.Name
71repoToName :: String -> Either String N.Name
53repoToName repo
72repoToName repo
54 | not (end `List.isSuffixOf` repo) = Left msg
73 | not (end `List.isSuffixOf` repo) = Left msg
@@ -86,8 +105,5 @@ withDeps handle path =
86 "could not find file " ++ path ++
105 "could not find file " ++ path ++
87 "\n You may need to create a dependency file for your project."
106 "\n You may need to create a dependency file for your project."
89−dependencies :: FilePath -> ErrorT String IO (Map.Map String String)
90−dependencies _ = return Map.empty -- withDeps deps
92depsAt :: FilePath -> ErrorT String IO Deps
108depsAt :: FilePath -> ErrorT String IO Deps
93depsAt = withDeps id
109depsAt = withDeps id