@@ -0,0 +1,78 @@
1+{-# LANGUAGE LambdaCase #-}
2+{-# LANGUAGE RecordWildCards #-}
3+{-# LANGUAGE TemplateHaskell #-}
5+module Stack.Config where
11+import Stack.Config.Yaml as Yaml
13+newtype StackResolver = StackResolver { fromStackResolver :: Text }
14+ deriving (Eq, Ord, Show)
16+makePrisms ''StackResolver
18+unStackResolver :: StackResolver -> String
19+unStackResolver = T.unpack . fromStackResolver
21+data RepoGit = RepoGit
24+ } deriving (Eq, Ord, Show)
30+ | StackRepoGit RepoGit
31+ deriving (Eq, Ord, Show)
33+makePrisms ''StackLocation
35+data StackPackage = StackPackage
36+ { _spLocation :: StackLocation
37+ , _spExtraDep :: Bool
38+ } deriving (Eq, Ord, Show)
40+makeLenses ''StackPackage
42+newtype StackExtraDep = StackExtraDep { fromStackExtraDep :: Text }
43+ deriving (Eq, Ord, Show)
45+makePrisms ''StackExtraDep
47+unExtraDep :: StackExtraDep -> String
48+unExtraDep = T.unpack . fromStackExtraDep
50+data StackConfig = StackConfig
51+ { _scResolver :: StackResolver
52+ , _scPackages :: [StackPackage]
53+ , _scExtraDeps :: [StackExtraDep]
54+ } deriving (Eq, Ord, Show)
56+makeLenses ''StackConfig
58+fromYamlConfig :: Yaml.Config -> StackConfig
59+fromYamlConfig c = StackConfig{..}
61+ _scResolver = coerce $ c ^. cResolver
62+ _scPackages = fromYamlPackage <$> c ^. cPackages
63+ _scExtraDeps = StackExtraDep <$> c ^. cExtraDeps
65+fromYamlPackage :: Yaml.Package -> StackPackage
66+fromYamlPackage = \case
68+ StackPackage (StackPath path) False
69+ Yaml.LocationSimple (Yaml.Location path extraDep) ->
70+ StackPackage (StackPath path) (fromMaybe False extraDep)
71+ Yaml.LocationGit (Location git extraDep) ->
72+ StackPackage (StackRepoGit $ fromYamlGit git) (fromMaybe False extraDep)
74+fromYamlGit :: Yaml.Git -> RepoGit
75+fromYamlGit yg = RepoGit{..}
78+ _rgCommit = yg ^. gCommit