Skip to content

Commit

Permalink
[#375] Remove deprecated stylish and contributing fields of the c…
Browse files Browse the repository at this point in the history
…onfig (#416)

Resolves #375
  • Loading branch information
vrom911 authored Feb 22, 2020
1 parent e1c7b55 commit 82c73a8
Show file tree
Hide file tree
Showing 11 changed files with 10 additions and 75 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ The changelog is available [on GitHub][2].
-}
```
* Improve `maintainer` field in the generated `.cabal` file.
* [#375](https://github.com/kowainik/summoner/issues/375):
Remove deprecated `stylish` and `contributing` fields in the configurations.
Use `files` instead.
(by [@vrom911](https://github.com/vrom911))

## 1.4.0.0 – Dec 25, 2019 🎅

Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,6 @@ Here is the list of the options that can be configured to suit your needs. If op
| `bench` | Bool | Create `benchmark` folder with `Main.hs` file with [`gauge`](https://hackage.haskell.org/package/gauge) library usage example? |
| `extensions` | [Text] | List of the default extensions to add into `default-extensions` section in the `.cabal`. |
| `ghc-options` | [Text] | List of the default GHC options to add into `ghc-options` section in the `.cabal`. |
| `stylish.*` | Text | **DEPRECATED** `stylish.file` to provide the absolute file path OR `stylish.url` to download the `.stylish-haskell.yaml` file to use in the project. |
| `contributing.*` | Text | **DEPRECATED** `contributing.file` to provide the absolute file path OR `contributing.url` download OR `contribuint.link` to link the `CONTRIBUTING.md` file to use in the project. |
| `files` | Map FilePath Source | Custom mapping of files to their sources. Represented as a list of inline tables in TOML in a format like `files = [ { path = "foo", url = "https://..." }, ... ]`. Supported file types: `url`, `local`, `raw`. |
|`[prelude]` | | |
| `package` | Text | The package name of the custom prelude you'd like to use in the project (doesn't work without `module` field). |
Expand Down
10 changes: 1 addition & 9 deletions summoner-cli/src/Summoner/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import Summoner.CustomPrelude (CustomPrelude (..), customPreludeT)
import Summoner.Decision (Decision (..))
import Summoner.GhcVer (GhcVer (..), parseGhcVer, showGhcVer)
import Summoner.License (LicenseName (..), parseLicenseName)
import Summoner.Source (Source, sourceCodec, sourceT)
import Summoner.Source (Source, sourceCodec)

import qualified Toml

Expand Down Expand Up @@ -75,8 +75,6 @@ data ConfigP (p :: Phase) = Config
, cExtensions :: ![Text]
, cGhcOptions :: ![Text] -- ^ GHC options to add to each stanza
, cGitignore :: ![Text]
, cStylish :: !(Last Source) -- ^ DEPRECATED: source to .stylish-haskell.yaml
, cContributing :: !(Last Source) -- ^ DEPRECATED: source to CONTRIBUTING.md
, cNoUpload :: !Any -- ^ Do not upload to the GitHub (even if enabled)
, cFiles :: !(Map FilePath Source) -- ^ Custom files
} deriving stock (Generic)
Expand Down Expand Up @@ -129,8 +127,6 @@ defaultConfig = Config
, cExtensions = []
, cGhcOptions = []
, cGitignore = []
, cStylish = Last Nothing
, cContributing = Last Nothing
, cNoUpload = Any False
, cFiles = mempty
}
Expand Down Expand Up @@ -158,8 +154,6 @@ configCodec = Config
<*> textArr "extensions" .= cExtensions
<*> textArr "ghc-options" .= cGhcOptions
<*> textArr "gitignore" .= cGitignore
<*> Toml.last sourceT "stylish" .= cStylish
<*> Toml.last sourceT "contributing" .= cContributing
<*> Toml.any "noUpload" .= cNoUpload
<*> filesCodec "files" .= cFiles
where
Expand Down Expand Up @@ -219,8 +213,6 @@ finalise Config{..} = Config
<*> pure cExtensions
<*> pure cGhcOptions
<*> pure cGitignore
<*> pure cStylish
<*> pure cContributing
<*> pure cNoUpload
<*> pure cFiles
where
Expand Down
11 changes: 0 additions & 11 deletions summoner-cli/src/Summoner/Project.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,6 @@ generateProject isOffline projectName Config{..} = do
when (oldGhcIncluded && settingsStack && settingsTravis) $
warningMessage "Old GHC versions won't be included into Stack matrix at Travis CI because of the Stack issue with newer Cabal versions."

let fetchLast :: Text -> Last Source -> IO (Maybe Text)
fetchLast option (Last mSource) = case mSource of
Nothing -> pure Nothing
Just source -> do
let msg = [text|The option '${option}' is deprecated. Use 'files' instead.|]
warningMessage msg
fetchSource isOffline source

settingsStylish <- fetchLast "stylish.{url,file,link}" cStylish
settingsContributing <- fetchLast "contributing.{url,file,link}" cContributing
settingsFiles <- fetchSources isOffline cFiles

-- Create project data from all variables in scope
Expand All @@ -138,7 +128,6 @@ generateProject isOffline projectName Config{..} = do
then decisionToBool decision ynPrompt
else falseMessage (yesNoTarget ynPrompt)


categoryText :: Text
categoryText =
[text|
Expand Down
2 changes: 0 additions & 2 deletions summoner-cli/src/Summoner/Settings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ data Settings = Settings
, settingsGitignore :: ![Text] -- ^ .gitignore file
, settingsCabal :: !Bool
, settingsStack :: !Bool
, settingsStylish :: !(Maybe Text) -- ^ @.stylish-haskell.yaml@ file
, settingsContributing :: !(Maybe Text) -- ^ @CONTRIBUTING.md@ file
, settingsNoUpload :: !Bool -- ^ do not upload to GitHub
, settingsFiles :: ![TreeFs] -- ^ Tree nodes of extra files
} deriving stock (Show)
Expand Down
18 changes: 1 addition & 17 deletions summoner-cli/src/Summoner/Source.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ This module contains the 'Source' data that describes how to fetch custom files.

module Summoner.Source
( Source (..)
, sourceT
, sourceCodec
, fetchSource
) where

import Control.Exception (catch)
import System.Process (readProcess)
import Toml (Key, TomlBiMap, TomlBiMapError (..), TomlCodec)
import Toml (TomlBiMapError (..), TomlCodec)

import Summoner.Ansi (errorMessage, infoMessage)

Expand Down Expand Up @@ -59,21 +58,6 @@ matchRaw :: Source -> Either TomlBiMapError Text
matchRaw (Raw raw) = Right raw
matchRaw e = Left $ WrongConstructor "Raw" $ showSource e

-- DEPRECATED: To be removed in 2.0
sourceT :: Key -> TomlCodec Source
sourceT nm = Toml.match (_Url >>> Toml._Text) (nm <> "url")
<|> Toml.match (_Local >>> Toml._String) (nm <> "Local")
<|> Toml.match (_Raw >>> Toml._Text) (nm <> "raw")
where
_Url :: TomlBiMap Source Text
_Url = Toml.prism Url matchUrl

_Local :: TomlBiMap Source FilePath
_Local = Toml.prism Local matchLocal

_Raw :: TomlBiMap Source Text
_Raw = Toml.prism Raw matchRaw

{- | This 'TomlCodec' is used in the @files@ field of config. It decodes
corresponding constructor from the top-level key.
-}
Expand Down
4 changes: 1 addition & 3 deletions summoner-cli/src/Summoner/Template/Doc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Maintainer: Kowainik <xrom.xkov@gmail.com>
Templates for various documentation files:
* CHANGELOG.md
* CONTRIBUTING.md
* LICENSE
* README.md
-}
Expand All @@ -26,8 +25,7 @@ docFiles :: Settings -> [TreeFs]
docFiles Settings{..} =
[ File "README.md" readme
, File "CHANGELOG.md" changelog ] ++
[ File "LICENSE" (unLicense settingsLicenseText) | hasLicense ] ++
maybeToList (File "CONTRIBUTING.md" <$> settingsContributing)
[ File "LICENSE" (unLicense settingsLicenseText) | hasLicense ]
where
hasLicense :: Bool
hasLicense = settingsLicenseName /= NONE
Expand Down
2 changes: 1 addition & 1 deletion summoner-cli/src/Summoner/Template/Haskell.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ haskellFiles Settings{..} = concat
, [ Dir "app" [exeFile] | settingsIsExe ]
, [ Dir "test" [testFile] | settingsTest ]
, [ Dir "benchmark" [benchmarkFile] | settingsBench ]
] ++ maybeToList (File ".stylish-haskell.yaml" <$> settingsStylish)
]
where
libFile :: TreeFs
libFile = File (toString libModuleName <> ".hs")
Expand Down
6 changes: 2 additions & 4 deletions summoner-cli/test/Test/Golden.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ fullProject = Settings
, settingsGhcOptions = ["-Wcompat", "-Widentities"]
, settingsCabal = True
, settingsStack = True
, settingsStylish = Just "This is stylish-haskell.yaml\n"
, settingsContributing = Just "This is contributing guide\n"
, settingsNoUpload = True
, settingsFiles =
[ File "extra.txt" "See full content of the file [here](@github)\n"
, Dir ".github" [File "CODEOWNERS" "* @chshersh @vrom911\n"]
, File ".stylish-haskell.yaml" "This is stylish-haskell.yaml\n"
, File "CONTRIBUTING.md" "This is contributing guide\n"
]
}
where
Expand Down Expand Up @@ -149,8 +149,6 @@ smallProject = Settings
, settingsGitignore = []
, settingsCabal = True
, settingsStack = False
, settingsStylish = Nothing
, settingsContributing = Nothing
, settingsNoUpload = True
, settingsFiles = mempty
}
Expand Down
11 changes: 0 additions & 11 deletions summoner-tui/src/Summoner/Tui.hs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ drawNew dirs kitForm = case kit ^. shouldSummon of
[ informationBlock
, validationBlock
, configBlock
, deprecationBlock
, fill ' '
]
where
Expand All @@ -248,9 +247,6 @@ drawNew dirs kitForm = case kit ^. shouldSummon of
infoTxt :: Text -> Widget SummonForm
infoTxt = withAttr "blue-fg" . txtWrap . (<>) ""

deprecationTxt :: Text -> Widget SummonForm
deprecationTxt = withAttr "yellow-fg" . txtWrap . (<>) ""

validationBlock :: Widget SummonForm
validationBlock = vBox $ case formErrorMessages dirs kitForm of
[] -> [withAttr "green-fg" $ str " ✔ Project configuration is valid"]
Expand All @@ -261,13 +257,6 @@ drawNew dirs kitForm = case kit ^. shouldSummon of
Nothing -> emptyWidget
Just file -> infoTxt $ toText file <> " file is used"

deprecationBlock :: Widget SummonForm
deprecationBlock = case (kit ^. stylish, kit ^. contributing) of
(Nothing, Nothing) -> emptyWidget
(s, c) -> vBox $
[ deprecationTxt "Option 'stylish' is deprecated, use 'files'" | isJust s ]
++ [ deprecationTxt "Option 'contributing' is deprecated, use 'files'" | isJust c]

help, helpBody :: Widget SummonForm
help = borderLabel "Help" (helpBody <+> fill ' ')
helpBody = vBox
Expand Down
15 changes: 0 additions & 15 deletions summoner-tui/src/Summoner/Tui/Kit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ module Summoner.Tui.Kit
, gitHub
, extensions
, ghcOptions
, stylish
, contributing
, offline
, shouldSummon
, configFile
Expand Down Expand Up @@ -79,7 +77,6 @@ import Summoner.Default (currentYear, defaultDescription, defaultGHC)
import Summoner.GhcVer (GhcVer)
import Summoner.License (LicenseName (..), customizeLicense, fetchLicense)
import Summoner.Settings (Settings (..))
import Summoner.Source (Source, fetchSource)
import Summoner.Template (createProjectTemplate)
import Summoner.Tree (TreeFs, showTree)

Expand All @@ -98,8 +95,6 @@ data SummonKit = SummonKit
, summonKitExtensions :: ![Text] -- ^ Can be recieved from the config file.
, summonKitGhcOptions :: ![Text] -- ^ Can be recieved from the config file.
, summonKitGitignore :: ![Text] -- ^ Received from the config file.
, summonKitStylish :: !(Maybe Source) -- ^ Can be recieved from the config file.
, summonKitContributing :: !(Maybe Source) -- ^ Can be recieved from the config file.
, summonKitOffline :: !Bool
, summonKitShouldSummon :: !Decision -- ^ Check if project needs to be created.
, summonKitConfigFile :: !(Maybe FilePath) -- ^ Just if configuration file was used.
Expand Down Expand Up @@ -188,8 +183,6 @@ summonKitToSettings sk = Settings
, settingsGitignore = sk ^. gitignore
, settingsCabal = sk ^. cabal
, settingsStack = sk ^. stack
, settingsStylish = "" <$ sk ^. stylish
, settingsContributing = "" <$ sk ^. contributing
, settingsNoUpload = sk ^. gitHub . noUpload
, settingsFiles = sk ^. extraFiles
}
Expand Down Expand Up @@ -217,15 +210,9 @@ finalSettings sk = do
(sk ^. user . fullName)
year

let fetch = maybe (pure Nothing) (fetchSource (sk ^. offline))
sStylish <- fetch $ sk ^. stylish
sContributing <- fetch $ sk ^. contributing

pure (summonKitToSettings sk)
{ settingsYear = year
, settingsLicenseText = licenseText
, settingsStylish = sStylish
, settingsContributing = sContributing
}

-- | Gets the initial 'SummonKit' from the given 'Config'.
Expand Down Expand Up @@ -270,8 +257,6 @@ configToSummonKit cRepo cOffline cConfigFile files Config{..} = SummonKit
, summonKitExtensions = cExtensions
, summonKitGhcOptions = cGhcOptions
, summonKitGitignore = cGitignore
, summonKitStylish = getLast cStylish
, summonKitContributing = getLast cContributing
, summonKitOffline = cOffline
, summonKitShouldSummon = Nop
, summonKitConfigFile = cConfigFile
Expand Down

0 comments on commit 82c73a8

Please sign in to comment.