Skip to content

Commit

Permalink
Improve OSS metadata, refactor (#381)
Browse files Browse the repository at this point in the history
* Improve OSS metadata, refactor

* Fix after review
  • Loading branch information
chshersh authored and vrom911 committed Nov 9, 2019
1 parent 3098e98 commit 0f85356
Show file tree
Hide file tree
Showing 35 changed files with 251 additions and 110 deletions.
53 changes: 0 additions & 53 deletions CONTRIBUTING.md

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ Here is the list of the options that can be configured to suit your needs. If op
| `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`, `file`, `raw`. |
| `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). |
| `module` | Text | The module name of the custom prelude you'd like to use in the project (doesn't work without `package` field). |
Expand Down
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
packages: summoner-cli/ summoner-tui/

tests: true
tests: True
1 change: 1 addition & 0 deletions summoner-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ The changelog is available [on GitHub][2].
want.
* [#327](https://github.com/kowainik/summoner/issues/327):
Better AppVeyor CI configuration for both `cabal` and `stack`.
* Rename `file` confing file of `source` to `local`.

## 1.3.0.1 — Apr 10, 2019

Expand Down
10 changes: 10 additions & 0 deletions summoner-cli/src/Summoner.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{- |
Copyright: (c) 2017-2019 Kowainik
SPDX-License-Identifier: MPL-2.0
Maintainer: Kowainik <xrom.xkov@gmail.com>
Main module that reexports all library components of the @summoner@.
-}

module Summoner
( module Summoner
) where
Expand All @@ -6,12 +14,14 @@ import Summoner.Ansi as Summoner
import Summoner.CLI as Summoner
import Summoner.Config as Summoner
import Summoner.CustomPrelude as Summoner
import Summoner.Decision as Summoner
import Summoner.Default as Summoner
import Summoner.GhcVer as Summoner
import Summoner.License as Summoner
import Summoner.Project as Summoner
import Summoner.Question as Summoner
import Summoner.Settings as Summoner
import Summoner.Source as Summoner
import Summoner.Template as Summoner
import Summoner.Text as Summoner
import Summoner.Tree as Summoner
8 changes: 7 additions & 1 deletion summoner-cli/src/Summoner/Ansi.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
-- | This module contains functions for colorful printing into terminal.
{- |
Copyright: (c) 2017-2019 Kowainik
SPDX-License-Identifier: MPL-2.0
Maintainer: Kowainik <xrom.xkov@gmail.com>
This module contains functions for colorful printing into terminal.
-}

module Summoner.Ansi
( Color (..)
Expand Down
8 changes: 7 additions & 1 deletion summoner-cli/src/Summoner/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}

-- | This module contains functions and data types to parse CLI inputs.
{- |
Copyright: (c) 2017-2019 Kowainik
SPDX-License-Identifier: MPL-2.0
Maintainer: Kowainik <xrom.xkov@gmail.com>
This module contains functions and data types to parse CLI inputs.
-}

module Summoner.CLI
( -- * CLI data types
Expand Down
8 changes: 7 additions & 1 deletion summoner-cli/src/Summoner/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}

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

module Summoner.Config
( ConfigP (..)
Expand Down
8 changes: 8 additions & 0 deletions summoner-cli/src/Summoner/CustomPrelude.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{- |
Copyright: (c) 2017-2019 Kowainik
SPDX-License-Identifier: MPL-2.0
Maintainer: Kowainik <xrom.xkov@gmail.com>
This module implements data type for representing custom alternative preludes.
-}

module Summoner.CustomPrelude
( CustomPrelude (..)
, customPreludeT
Expand Down
8 changes: 7 additions & 1 deletion summoner-cli/src/Summoner/Decision.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
-- | Decision data type.
{- |
Copyright: (c) 2017-2019 Kowainik
SPDX-License-Identifier: MPL-2.0
Maintainer: Kowainik <xrom.xkov@gmail.com>
Decision data type.
-}

module Summoner.Decision
( Decision (..)
Expand Down
8 changes: 7 additions & 1 deletion summoner-cli/src/Summoner/Default.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
-- | This module contains some default values to use.
{- |
Copyright: (c) 2017-2019 Kowainik
SPDX-License-Identifier: MPL-2.0
Maintainer: Kowainik <xrom.xkov@gmail.com>
This module contains some default values to use.
-}

module Summoner.Default
( defaultGHC
Expand Down
7 changes: 6 additions & 1 deletion summoner-cli/src/Summoner/GhcVer.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{- | Contains data type for GHC versions supported by Summoner
{- |
Copyright: (c) 2017-2019 Kowainik
SPDX-License-Identifier: MPL-2.0
Maintainer: Kowainik <xrom.xkov@gmail.com>
Contains data type for GHC versions supported by Summoner
and some useful functions for manipulation with them.
-}

Expand Down
10 changes: 8 additions & 2 deletions summoner-cli/src/Summoner/License.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
-- | Data types that represent license names and license content and functions
-- to work with them.
{- |
Copyright: (c) 2017-2019 Kowainik
SPDX-License-Identifier: MPL-2.0
Maintainer: Kowainik <xrom.xkov@gmail.com>
Data types that represent license names and license content and functions
to work with them.
-}

module Summoner.License
( LicenseName(..)
Expand Down
8 changes: 7 additions & 1 deletion summoner-cli/src/Summoner/Project.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{-# LANGUAGE QuasiQuotes #-}

-- | This module introduces functions for the project creation.
{- |
Copyright: (c) 2017-2019 Kowainik
SPDX-License-Identifier: MPL-2.0
Maintainer: Kowainik <xrom.xkov@gmail.com>
This module introduces functions for the project creation.
-}

module Summoner.Project
( generateProject
Expand Down
8 changes: 7 additions & 1 deletion summoner-cli/src/Summoner/Question.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}

-- | This module contains function to proper questioning in terminal.
{- |
Copyright: (c) 2017-2019 Kowainik
SPDX-License-Identifier: MPL-2.0
Maintainer: Kowainik <xrom.xkov@gmail.com>
This module contains function to proper questioning in terminal.
-}

module Summoner.Question
( -- * Choose functions.
Expand Down
8 changes: 8 additions & 0 deletions summoner-cli/src/Summoner/Settings.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{- |
Copyright: (c) 2017-2019 Kowainik
SPDX-License-Identifier: MPL-2.0
Maintainer: Kowainik <xrom.xkov@gmail.com>
Complete settings required for the project creation.
-}

module Summoner.Settings
( Settings (..)

Expand Down
40 changes: 24 additions & 16 deletions summoner-cli/src/Summoner/Source.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{- |
Copyright: (c) 2017-2019 Kowainik
SPDX-License-Identifier: MPL-2.0
Maintainer: Kowainik <xrom.xkov@gmail.com>
This module contains the 'Source' data that describes how to fetch custom files.
-}

module Summoner.Source
( Source (..)
, sourceT
Expand All @@ -24,7 +32,7 @@ data Source

{- | File path to the local source file.
-}
| File !FilePath
| Local !FilePath

{- | Raw file text content.
-}
Expand All @@ -33,19 +41,19 @@ data Source

showSource :: Source -> Text
showSource = \case
Url _ -> "Url"
File _ -> "File"
Raw _ -> "Raw"
Url _ -> "Url"
Local _ -> "Local"
Raw _ -> "Raw"

-- TODO: return Maybe
matchUrl :: Source -> Either TomlBiMapError Text
matchUrl (Url url) = Right url
matchUrl e = Left $ WrongConstructor "Url" $ showSource e

-- TODO: return Maybe
matchFile :: Source -> Either TomlBiMapError FilePath
matchFile (File file) = Right file
matchFile e = Left $ WrongConstructor "File" $ showSource e
matchLocal :: Source -> Either TomlBiMapError FilePath
matchLocal (Local file) = Right file
matchLocal e = Left $ WrongConstructor "Local" $ showSource e

-- TODO: return Maybe
matchRaw :: Source -> Either TomlBiMapError Text
Expand All @@ -54,15 +62,15 @@ 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 (_File >>> Toml._String) (nm <> "file")
<|> Toml.match (_Raw >>> Toml._Text) (nm <> "raw")
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

_File :: TomlBiMap Source FilePath
_File = Toml.prism File matchFile
_Local :: TomlBiMap Source FilePath
_Local = Toml.prism Local matchLocal

_Raw :: TomlBiMap Source Text
_Raw = Toml.prism Raw matchRaw
Expand All @@ -73,20 +81,20 @@ corresponding constructor from the top-level key.
sourceCodec :: TomlCodec Source
sourceCodec = asum
[ Toml.dimatch (rightToMaybe . matchUrl) Url (Toml.text "url")
, Toml.dimatch (rightToMaybe . matchFile) File (Toml.string "file")
, Toml.dimatch (rightToMaybe . matchLocal) Local (Toml.string "local")
, Toml.dimatch (rightToMaybe . matchRaw) Raw (Toml.text "raw")
]

fetchSource :: Bool -> Source -> IO (Maybe Text)
fetchSource isOffline = \case
File path -> catch (Just <$> readFileText path) (fileError path)
Local path -> catch (Just <$> readFileText path) (localError path)
Url url -> if isOffline
then Nothing <$ infoMessage ("Ignoring fetching from URL in offline mode from source: " <> url)
else fetchUrl url `catch` urlError url
Raw raw -> pure $ Just raw
where
fileError :: FilePath -> SomeException -> IO (Maybe Text)
fileError path _ = errorMessage ("Couldn't read file: " <> toText path)
localError :: FilePath -> SomeException -> IO (Maybe Text)
localError path _ = errorMessage ("Couldn't read file: " <> toText path)
>> pure Nothing

urlError :: Text -> SomeException -> IO (Maybe Text)
Expand Down
8 changes: 7 additions & 1 deletion summoner-cli/src/Summoner/Template.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
-- | This module contains functions for stack template creation.
{- |
Copyright: (c) 2017-2019 Kowainik
SPDX-License-Identifier: MPL-2.0
Maintainer: Kowainik <xrom.xkov@gmail.com>
This module contains functions for the Haskell project template creation.
-}

module Summoner.Template
( createProjectTemplate
Expand Down
8 changes: 7 additions & 1 deletion summoner-cli/src/Summoner/Template/Cabal.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{-# LANGUAGE QuasiQuotes #-}

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

module Summoner.Template.Cabal
( cabalFile
Expand Down
13 changes: 13 additions & 0 deletions summoner-cli/src/Summoner/Template/Doc.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
{- |
Copyright: (c) 2017-2019 Kowainik
SPDX-License-Identifier: MPL-2.0
Maintainer: Kowainik <xrom.xkov@gmail.com>
Templates for various documentation files:
* CHANGELOG.md
* CONTRIBUTING.md
* LICENSE
* README.md
-}

module Summoner.Template.Doc
( docFiles
) where
Expand Down
Loading

0 comments on commit 0f85356

Please sign in to comment.