hi 1.1.0.1 → 1.1.0.2
raw patch · 5 files changed
+46/−27 lines, 5 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Hi.Types: instance Eq File
+ Hi.Types: instance Ord File
Files
- hi.cabal +1/−1
- src/Hi.hs +31/−21
- src/Hi/CommandLineOption.hs +3/−1
- src/Hi/Template.hs +10/−3
- src/Hi/Types.hs +1/−1
hi.cabal view
@@ -1,5 +1,5 @@ name: hi-version: 1.1.0.1+version: 1.1.0.2 cabal-version: >=1.8 build-type: Simple license: BSD3
src/Hi.hs view
@@ -1,34 +1,37 @@-{-# LANGUAGE NamedFieldPuns, RecordWildCards #-}+{-# LANGUAGE NamedFieldPuns #-}+{-# LANGUAGE RecordWildCards #-} module Hi ( run , process ) where -import Hi.Directory (inDirectory)-import Hi.FilePath (rewritePath)-import qualified Hi.Git as Git-import Hi.Template (readTemplates)+import Hi.Directory (inDirectory)+import Hi.FilePath (rewritePath)+import qualified Hi.Git as Git+import Hi.Template (readTemplates) import Hi.Types import Control.Applicative import Control.Monad-import qualified Data.ByteString as BS (writeFile, concat)-import qualified Data.ByteString.Lazy as LBS (toChunks)-import Data.Maybe (fromJust)-import qualified Data.Text as T (pack, unpack)-import Data.Text.Encoding (decodeUtf8)-import Data.Text.Lazy.Encoding (encodeUtf8)-import Data.Text.Template (Context, substitute)-import System.Directory (createDirectoryIfMissing)-import System.FilePath (dropFileName, joinPath, splitPath, normalise)-import System.Process (system)+import qualified Data.ByteString.Char8 as BS+import qualified Data.ByteString.Lazy as LBS (toChunks)+import Data.List ((\\))+import Data.Maybe (fromJust)+import qualified Data.Text as T (pack, unpack)+import Data.Text.Encoding (decodeUtf8)+import Data.Text.Lazy.Encoding (encodeUtf8)+import Data.Text.Template (Context, substitute)+import System.Directory (createDirectoryIfMissing)+import System.FilePath (dropFileName, joinPath, normalise,+ splitPath)+import System.Process (system) -- | Run 'hi'. run :: Option -> IO () run option@(Option {templateSource}) = do putStrLn $ "Creating new project with " ++ sourceName templateSource- writeFiles =<< showFileList =<< process option . dropExtraRegularFiles <$> readTemplates templateSource+ writeFiles =<< showFileList =<< process option <$> readTemplates templateSource postProcess option where sourceName (FromRepo repository) = "git repository:" ++ Git.expandUrl repository@@ -56,11 +59,11 @@ -- |Process given 'Files' and return result. it does ----- 1. rewrite path------ 2. substitute arguments+-- 1. Rewrite path+-- 2. Substitute arguments+-- 3. Drop regular files if template file with same name exists process :: Option -> Files -> Files-process Option {..} = map go+process Option {..} = dropExtraRegularFiles . map go where go (TemplateFile path content) = TemplateFile (rewritePath' path) (substitute' content) go (RegularFile path content) = RegularFile (rewritePath' path) content@@ -83,12 +86,19 @@ void $ inDirectory packageName $ forM_ afterCommands (void . system) -- | Drop 'RegularFile's if there is a 'TemplateFile' which has same name+--+-- >>> dropExtraRegularFiles [TemplateFile "foo" (BS.pack "e"), RegularFile "foo" (BS.pack "e")]+-- [TemplateFile {getFilePath = "foo", getFileContents = "e"}]+--+-- >>> dropExtraRegularFiles [RegularFile "foo" (BS.pack "e")]+-- [RegularFile {getFilePath = "foo", getFileContents = "e"}]+-- dropExtraRegularFiles :: Files -> Files dropExtraRegularFiles [] = [] dropExtraRegularFiles xs = go (map getFilePath xs) xs where go _ [] = []- go paths (y@(RegularFile p _):ys) = if p `elem` paths+ go paths (y@(RegularFile p _):ys) = if p `elem` (paths \\ [p]) then go paths ys else y : go paths ys go paths (y@(TemplateFile _ _):ys) = y : go paths ys
src/Hi/CommandLineOption.hs view
@@ -20,7 +20,9 @@ commandLineOption :: Parser CommandLineOption commandLineOption = CommandLineOption <$> (strOption (short 'p' <> long "package-name" <> help "Name of package") <|> argument str (help "Name of package"))- <*> optional (strOption (short 'm' <> long "moduleName" <> help "Name of Module"))+ -- TODO: Deprecate and remove "moduleName" option+ -- https://github.com/fujimura/hi/issues/48+ <*> optional (strOption (short 'm' <> long "moduleName" <> long "module-name" <> help "Name of Module")) <*> optional (strOption (short 'a' <> long "author" <> help "Name of the project's author")) <*> optional (strOption (short 'e' <> long "email" <> help "Email address of the maintainer")) <*> strOption (short 'r' <> long "repository" <> help "Template repository" <> value defaultRepo)
src/Hi/Template.hs view
@@ -14,12 +14,19 @@ import qualified Data.ByteString as BS (readFile) import Data.List (isSuffixOf) import Data.List.Split (splitOn)+import System.Directory (canonicalizePath, doesDirectoryExist) --- | Read templates in given 'FilePath'+-- | Read templates in given 'TemplateSource' readTemplates :: TemplateSource -> IO Files-readTemplates (FromRepo repo) =+readTemplates (FromRepo repo) = do+ e <- doesDirectoryExist repo+ repo' <- if e+ -- It seems to be an file path+ then canonicalizePath repo+ -- Not looks like a file path+ else return repo inTemporaryDirectory "hi" $ do- Git.clone $ Git.expandUrl repo+ Git.clone $ Git.expandUrl repo' paths <- Git.lsFiles mapM fetchFile paths
src/Hi/Types.hs view
@@ -10,7 +10,7 @@ import Data.ByteString (ByteString) data File = TemplateFile { getFilePath :: FilePath, getFileContents :: ByteString } |- RegularFile { getFilePath :: FilePath, getFileContents :: ByteString } deriving (Show)+ RegularFile { getFilePath :: FilePath, getFileContents :: ByteString } deriving (Eq,Ord,Show) data TemplateSource = FromRepo String deriving (Eq,Ord,Show)