{- |
Copyright: (c) 2017-2019 Kowainik
SPDX-License-Identifier: MPL-2.0
Maintainer: Kowainik <xrom.xkov@gmail.com>

Templates for @stack.yaml@ files.
-}

module Summoner.Template.Stack
       ( stackFiles
       ) where

import Summoner.Default (defaultGHC)
import Summoner.GhcVer (GhcVer (..), latestLts, showGhcVer)
import Summoner.Settings (Settings (..))
import Summoner.Tree (TreeFs (..))


stackFiles :: Settings -> [TreeFs]
stackFiles :: Settings -> [TreeFs]
stackFiles Settings{..} = (GhcVer -> TreeFs) -> [GhcVer] -> [TreeFs]
forall a b. (a -> b) -> [a] -> [b]
map GhcVer -> TreeFs
createStackYaml [GhcVer]
settingsTestedVersions
 where
    -- create @stack.yaml@ file with LTS corresponding to specified ghc version
    createStackYaml :: GhcVer -> TreeFs
    createStackYaml :: GhcVer -> TreeFs
createStackYaml ghcV :: GhcVer
ghcV = FilePath -> Text -> TreeFs
File (Text -> FilePath
forall a. ToString a => a -> FilePath
toString (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ "stack" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
ver Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ".yaml")
        (Text -> TreeFs) -> Text -> TreeFs
forall a b. (a -> b) -> a -> b
$ "resolver: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> GhcVer -> Text
latestLts GhcVer
ghcV Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "\n"
      where
        ver :: Text
        ver :: Text
ver = if GhcVer
ghcV GhcVer -> GhcVer -> Bool
forall a. Eq a => a -> a -> Bool
== GhcVer
defaultGHC
              then ""
              else "-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> GhcVer -> Text
showGhcVer GhcVer
ghcV