templatise 0.1.0.3 → 0.1.1.0
raw patch · 6 files changed
+33/−25 lines, 6 filesdep ~basedep ~filepathdep ~tastyPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: base, filepath, tasty, text
API changes (from Hackage documentation)
- Cabal: convert :: ByteString -> Initialise String
+ Cabal: convert :: ByteString -> Initialise Text
- Git: config :: String -> IO Text
+ Git: config :: Text -> IO Text
Files
- lib/initialise/Cabal.hs +16/−14
- lib/initialise/Defaults.hs +1/−0
- lib/initialise/Git.hs +3/−3
- templatise.cabal +9/−7
- test/initialise/CabalGolden.hs +2/−1
- test/initialise/GitSpec.hs +2/−0
lib/initialise/Cabal.hs view
@@ -10,9 +10,11 @@ import Control.Monad.Catch (throwM) import Control.Monad.Reader (asks, liftIO) import Data.ByteString (ByteString, append, breakSubstring, concat, readFile, stripPrefix)-import Data.ByteString.Char8 (pack)-import Data.Text (Text, unpack)+import qualified Data.ByteString.Char8 as BS (pack)+import Data.Text (Text, unlines)+import qualified Data.Text as T (pack, unpack) import Data.Text.Encoding (encodeUtf8)+import Data.Text.IO (writeFile) import Distribution.Fields ( CommentPosition (NoComment), Field (Field, Section),@@ -30,7 +32,7 @@ import System.Directory.Extra (createDirectoryIfMissing, removeDirectoryRecursive, removeFile) import System.FilePath (replaceBaseName, (</>)) import Text.Parsec.Error (ParseError)-import Prelude hiding (concat, readFile)+import Prelude hiding (concat, readFile, unlines, writeFile) instance Exception ParseError @@ -44,7 +46,7 @@ replaceCabal :: FilePath -> Initialise () replaceCabal path = do -- TODO handle in replaceWith- path' <- asks (flip replaceBaseName path . unpack . name)+ path' <- asks (flip replaceBaseName path . T.unpack . name) -- TODO replaceWith convert contents <- liftIO $ readFile path contents' <- convert contents@@ -52,10 +54,10 @@ -- TODO handle in replaceWith liftIO $ removeFile path -convert :: ByteString -> Initialise String+convert :: ByteString -> Initialise Text convert contents = do fs <- either throwM pure (readFields contents)- showFields (const NoComment) . fromParsecFields <$> mapM convert' fs+ T.pack . showFields (const NoComment) . fromParsecFields <$> mapM convert' fs convert' :: Field Position -> Initialise (Field Position) convert' f@(Field n@(Name _ fName) ls) = do@@ -64,12 +66,12 @@ -- package "name" -> field (encodeUtf8 name) "version" -> field "0.1.0.0"- "license" -> field (pack $ licenseId licence)- "copyright" -> field (pack $ unwords ["(c)", show year, unpack author])+ "license" -> field (BS.pack $ licenseId licence)+ "copyright" -> field (BS.pack $ unwords ["(c)", show year, T.unpack author]) "author" -> field (encodeUtf8 author) "maintainer" -> field (encodeUtf8 maintainer)- "homepage" -> field $ pack $ show homepage- "bug-reports" -> field $ pack (show homepage ++ "/issues")+ "homepage" -> field $ BS.pack $ show homepage+ "bug-reports" -> field $ BS.pack (show homepage ++ "/issues") "synopsis" -> field "TODO" "description" -> field "TODO" -- common@@ -79,7 +81,7 @@ "build-depends" -> pure $ Field n $ map (convertFieldLine name) ls "hs-source-dirs" -> pure $ Field n $ map (convertFieldLine name) ls -- source-repository- "location" -> field $ pack $ show homepage+ "location" -> field $ BS.pack $ show homepage _ -> pure f where field s = pure $ Field n [FieldLine annotation s]@@ -110,7 +112,7 @@ replaceDirectoryWith :: FilePath -> (FilePath -> Initialise ()) -> Initialise () replaceDirectoryWith component r = do name' <- asks name- path' <- asks ((</> component </> unpack name') . path)+ path' <- asks ((</> component </> T.unpack name') . path) liftIO $ createDirectoryIfMissing True path' r path' liftIO $ removeDirectoryRecursive $ replaceBaseName "initialise" path'@@ -130,7 +132,7 @@ "import Test.Tasty (defautMain, testGroup)", "", "main :: IO ()",- "main = defaultMain $ testGroup \"" ++ unpack name' ++ "-library\" []"+ "main = defaultMain $ testGroup \"" <> name' <> "-library\" []" ] replaceBin :: FilePath -> Initialise ()@@ -143,5 +145,5 @@ [ "module Main (main) where", "", "main :: IO ()",- "main = putStrLn " ++ unpack name'+ "main = putStrLn " <> name' ]
lib/initialise/Defaults.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} module Defaults
lib/initialise/Git.hs view
@@ -1,7 +1,7 @@ module Git (config) where -import Data.Text (Text, pack)+import Data.Text (Text, pack, unpack) import System.Process (readProcess) -config :: String -> IO Text-config key = pack . head . lines <$> readProcess "git" ["config", key] ""+config :: Text -> IO Text+config key = pack . head . lines <$> readProcess "git" ["config", unpack key] ""
templatise.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: templatise-version: 0.1.0.3+version: 0.1.1.0 license: Unlicense license-file: LICENSE copyright: (c) 2023 Alex Brandt@@ -23,8 +23,10 @@ || ==9.4.5 || ==9.4.6 || ==9.4.7+ || ==9.4.8 || ==9.6.2 || ==9.6.3+ || ==9.8.1 extra-source-files: CHANGELOG.md@@ -42,15 +44,15 @@ common initialise-common build-depends:- , base ^>=4.16.3.0 || ^>=4.17.0.0 || ^>=4.18.0.0+ , base >=4.16.3.0 && <4.20 , bytestring ^>=0.11.3.1 || ^>=0.12.0.2 , Cabal-syntax ^>=3.8.1.0 || ^>=3.10.1.0- , filepath ^>=1.4.2.2+ , filepath >=1.4.2.2 && <1.6 , mtl ^>=2.2.2 || ^>=2.3.1 , network-uri ^>=2.6.4.1 || ^>=2.7.0.0 , optparse-applicative ^>=0.18.1.0 , process ^>=1.6.13.2- , text ^>=1.2.5.0 || >=2.0.2 && <2.1 || ^>=2.1+ , text ^>=1.2.5.0 || ^>=2.0.2 || ^>=2.1 library initialise-library import: initialise-common@@ -90,7 +92,7 @@ , directory ^>=1.3.6.2 , hspec ^>=2.11.4 , initialise-library- , tasty >=1.4.3 && <1.5 || ^>=1.5+ , tasty ^>=1.4.3 || ^>=1.5 , tasty-golden ^>=2.3.5 , tasty-hspec ^>=1.2.0.4 , temporary ^>=1.3@@ -115,8 +117,8 @@ executable initialise main-is: Main.hs build-depends:- , base ^>=4.16.3.0 || ^>=4.17.0.0 || ^>=4.18.0.0- , filepath ^>=1.4.2.2+ , base ^>=4.16.3.0 || ^>=4.17.0.0 || ^>=4.18.0.0 || ^>=4.19.0.0+ , filepath ^>=1.4.2.2 || ^>=1.5.0 , initialise-library , optparse-applicative ^>=0.18.1.0
test/initialise/CabalGolden.hs view
@@ -8,6 +8,7 @@ import Data.ByteString (readFile) import Data.ByteString.Lazy.Char8 (pack) import Data.Maybe (fromJust)+import Data.Text (unpack) import Distribution.SPDX.LicenseId (LicenseId (MIT)) import Initialise (runInitialise) import Network.URI (parseURI)@@ -33,7 +34,7 @@ gold = p `replaceExtension` ".golden.cabal" action = do contents <- liftIO (readFile p)- pack <$> runInitialise (SUT.convert contents) configuration+ pack . unpack <$> runInitialise (SUT.convert contents) configuration configuration = Configuration { name = "sentinel",
test/initialise/GitSpec.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE OverloadedStrings #-}+ module GitSpec (spec) where import Data.Text (pack)