2023-12-23 22:15:10 +01:00
|
|
|
{- This Source Code Form is subject to the terms of the Mozilla Public License,
|
|
|
|
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
|
|
|
obtain one at https://mozilla.org/MPL/2.0/. -}
|
|
|
|
|
2023-12-12 18:51:44 +01:00
|
|
|
-- | Configuration file.
|
2023-08-09 20:59:42 +02:00
|
|
|
module SlackBuilder.Config
|
2024-11-14 22:58:14 +01:00
|
|
|
( CloneSettings(..)
|
|
|
|
, DownloaderSettings(..)
|
2024-10-01 19:54:32 +02:00
|
|
|
, Settings(..)
|
2023-08-28 21:05:47 +02:00
|
|
|
, MaintainerSettings(..)
|
2024-09-20 22:34:17 +02:00
|
|
|
, PackageSettings(..)
|
2023-08-09 20:59:42 +02:00
|
|
|
, settingsCodec
|
|
|
|
) where
|
|
|
|
|
2024-05-11 19:01:41 +02:00
|
|
|
import Data.List.NonEmpty (NonEmpty(..))
|
2023-08-09 20:59:42 +02:00
|
|
|
import Data.Text (Text)
|
|
|
|
import Toml ((.=))
|
|
|
|
import qualified Toml
|
2024-10-01 19:54:32 +02:00
|
|
|
import GHC.Records (HasField(..))
|
2023-08-09 20:59:42 +02:00
|
|
|
|
2023-08-15 10:33:19 +02:00
|
|
|
data Settings = Settings
|
|
|
|
{ ghToken :: !Text
|
|
|
|
, repository :: !FilePath
|
|
|
|
, branch :: Text
|
2023-08-17 22:07:09 +02:00
|
|
|
, downloadURL :: Text
|
2024-05-11 19:01:41 +02:00
|
|
|
, uploadCommand :: NonEmpty Text
|
2023-08-28 21:05:47 +02:00
|
|
|
, maintainer :: MaintainerSettings
|
2024-09-20 22:34:17 +02:00
|
|
|
, packages :: [PackageSettings]
|
2023-08-28 21:05:47 +02:00
|
|
|
} deriving (Eq, Show)
|
|
|
|
|
2023-10-08 12:28:46 +02:00
|
|
|
newtype MaintainerSettings = MaintainerSettings
|
|
|
|
{ signature :: Bool
|
2023-08-09 20:59:42 +02:00
|
|
|
} deriving (Eq, Show)
|
|
|
|
|
2024-10-01 19:54:32 +02:00
|
|
|
data DownloaderSettings = DownloaderSettings
|
2024-09-20 22:34:17 +02:00
|
|
|
{ name :: Text
|
|
|
|
, is64 :: Bool
|
2024-09-30 14:39:38 +02:00
|
|
|
, version :: Text
|
2024-11-14 22:58:14 +01:00
|
|
|
, template :: Maybe Text
|
|
|
|
, clone :: Maybe CloneSettings
|
2024-09-22 18:07:22 +02:00
|
|
|
, github :: Maybe (Text, Text)
|
|
|
|
, packagist :: Maybe (Text, Text)
|
2024-09-27 12:20:34 +02:00
|
|
|
, text :: Maybe (Text, [String])
|
2024-09-29 21:24:40 +02:00
|
|
|
, repackage :: Maybe [String]
|
2024-09-20 22:34:17 +02:00
|
|
|
} deriving (Eq, Show)
|
|
|
|
|
2024-11-14 22:58:14 +01:00
|
|
|
data PackageSettings = PackageSettings
|
2024-10-01 19:54:32 +02:00
|
|
|
{ downloader :: DownloaderSettings
|
2024-11-14 22:58:14 +01:00
|
|
|
, downloaders :: [DownloaderSettings]
|
|
|
|
} deriving (Eq, Show)
|
|
|
|
|
|
|
|
data CloneSettings = CloneSettings
|
|
|
|
{ remote :: Text
|
|
|
|
, tagTemplate :: Text
|
2024-10-01 19:54:32 +02:00
|
|
|
} deriving (Eq, Show)
|
|
|
|
|
2023-08-09 20:59:42 +02:00
|
|
|
settingsCodec :: Toml.TomlCodec Settings
|
|
|
|
settingsCodec = Settings
|
|
|
|
<$> Toml.text "gh_token" .= ghToken
|
2023-08-15 10:33:19 +02:00
|
|
|
<*> Toml.string "repository" .= repository
|
|
|
|
<*> Toml.text "branch" .= branch
|
2023-08-17 22:07:09 +02:00
|
|
|
<*> Toml.text "download_url" .= downloadURL
|
2024-05-11 19:01:41 +02:00
|
|
|
<*> Toml.arrayNonEmptyOf Toml._Text "upload_command" .= uploadCommand
|
2023-08-28 21:05:47 +02:00
|
|
|
<*> Toml.table maintainerSettingsCodec "maintainer" .= maintainer
|
2024-09-20 22:34:17 +02:00
|
|
|
<*> Toml.list packageSettingsCodec "package" .= packages
|
2023-08-28 21:05:47 +02:00
|
|
|
|
|
|
|
maintainerSettingsCodec :: Toml.TomlCodec MaintainerSettings
|
|
|
|
maintainerSettingsCodec = MaintainerSettings
|
2023-10-08 12:28:46 +02:00
|
|
|
<$> Toml.bool "signature" .= signature
|
2024-09-20 22:34:17 +02:00
|
|
|
|
2024-10-01 19:54:32 +02:00
|
|
|
downloaderSettingsCodec :: Toml.TomlCodec DownloaderSettings
|
|
|
|
downloaderSettingsCodec = DownloaderSettings
|
2024-09-20 22:34:17 +02:00
|
|
|
<$> Toml.text "name" .= name
|
|
|
|
<*> Toml.bool "is64" .= is64
|
2024-09-30 14:39:38 +02:00
|
|
|
<*> Toml.text "version" .= version
|
2024-11-14 22:58:14 +01:00
|
|
|
<*> Toml.dioptional (Toml.text "template") .= template
|
|
|
|
<*> Toml.dioptional (Toml.table cloneSettingsCodec "clone") .= clone
|
2024-09-27 12:20:34 +02:00
|
|
|
<*> Toml.dioptional (Toml.table githubCodec "github") .= github
|
|
|
|
<*> Toml.dioptional (Toml.table packagistCodec "packagist") .= packagist
|
2024-09-29 21:24:40 +02:00
|
|
|
<*> Toml.dioptional (Toml.table textCodec "text") .= text
|
|
|
|
<*> Toml.dioptional (Toml.arrayOf Toml._String "repackage") .= repackage
|
2024-09-27 12:20:34 +02:00
|
|
|
where
|
|
|
|
githubCodec = Toml.pair (Toml.text "owner") (Toml.text "name")
|
|
|
|
packagistCodec = Toml.pair (Toml.text "owner") (Toml.text "name")
|
|
|
|
textCodec = Toml.pair (Toml.text "url") (Toml.arrayOf Toml._String "picker")
|
2024-10-01 19:54:32 +02:00
|
|
|
|
|
|
|
packageSettingsCodec :: Toml.TomlCodec PackageSettings
|
2024-11-14 22:58:14 +01:00
|
|
|
packageSettingsCodec = PackageSettings
|
|
|
|
<$> downloaderSettingsCodec .= getField @"downloader"
|
|
|
|
<*> Toml.list downloaderSettingsCodec "downloader" .= downloaders
|
|
|
|
|
|
|
|
cloneSettingsCodec :: Toml.TomlCodec CloneSettings
|
|
|
|
cloneSettingsCodec = CloneSettings
|
|
|
|
<$> Toml.text "remote" .= remote
|
|
|
|
<*> Toml.text "tag_template" .= tagTemplate
|