Skip to content

Commit e1ed04d

Browse files
committed
Stop built-in default templates
Pros: - This made code complex - Default template which can be forked seems to be useful Cons: - A bit slow - Version conflict between hi and template may exist
1 parent 92287c6 commit e1ed04d

23 files changed

+16
-270
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "test/template"]
2+
path = test/template
3+
url = git://github.com/fujimura/hi-hspec.git

hi.cabal

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,6 @@ category: Distribution
99
build-type: Simple
1010
cabal-version: >=1.8
1111
homepage: https://github.com/fujimura/hi
12-
data-files:
13-
templates/flat/.gitignore.template
14-
templates/flat/LICENSE.template
15-
templates/flat/Main.hs.template
16-
templates/flat/ModuleName.hs.template
17-
templates/flat/README.md.template
18-
templates/flat/package-name.cabal.template
19-
templates/hspec/.gitignore.template
20-
templates/hspec/LICENSE.template
21-
templates/hspec/README.md.template
22-
templates/hspec/package-name.cabal.template
23-
templates/hspec/src/ModuleName.hs.template
24-
templates/hspec/src/ModuleName/Internal.hs.template
25-
templates/hspec/test/ModuleNameSpec.hs.template
26-
templates/hspec/test/Spec.hs.template
2712
description:
2813
This application generates a scaffold for Haskell project from a Git repository.
2914

src/Hi.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ run option@(Option {templateSource}) = do
3232
postProcess option
3333
where
3434
sourceName (FromRepo repository) = "git repository:" ++ Git.expandUrl repository
35-
sourceName BuiltInHSpec = "built in template: HSpec"
36-
sourceName BuiltInFlat = "built in template: Flat"
3735

3836
-- |Write given 'Files' to filesystem.
3937
writeFiles :: Files -> IO ()

src/Hi/CommandLineOption.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ data CommandLineOption = CommandLineOption
1010
, packageName :: Maybe String
1111
, author :: Maybe String
1212
, email :: Maybe String
13-
, template :: Maybe String
1413
, repository :: Maybe String
1514
, configFilePath :: Maybe String
1615
, initializeGitRepository :: Maybe Bool
@@ -22,7 +21,6 @@ commandLineOption = CommandLineOption
2221
<*> optional ( strOption ( short 'p' <> long "packageName" <> metavar "package-name" <> help "Name of package" ))
2322
<*> optional ( strOption ( short 'a' <> long "author" <> metavar "NAME" <> help "Name of the project's author" ))
2423
<*> optional ( strOption ( short 'e' <> long "email" <> metavar "EMAIL" <> help "Email address of the maintainer" ))
25-
<*> optional ( strOption ( short 't' <> long "template" <> metavar "hspec/flat" <> help "Template to be used" ))
2624
<*> optional ( strOption ( short 'r' <> long "repository" <> metavar "REPOSITORY" <> help "Template repository" ))
2725
<*> optional ( strOption ( long "configuration-file" <> help "Use specified configuration file"))
2826
<*> optional ( switch ( long "initialize-git-repository" <> help "Initialize with git repository"))

src/Hi/Option.hs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,7 @@ buildOption copt = do
7878
(y,_,_) <- (toGregorian . utctDay) <$> getCurrentTime
7979
return $ show y
8080
guessTemplate :: IO TemplateSource
81-
guessTemplate = do
82-
return $ case CommandLineOption.template copt of
83-
Just "hspec" -> BuiltInHSpec
84-
Just "flat" -> BuiltInFlat
85-
_ -> fromMaybe BuiltInHSpec $ FromRepo <$> CommandLineOption.repository copt
81+
guessTemplate = return . FromRepo $ maybe defaultRepo id (CommandLineOption.repository copt)
8682

8783
defaultRepo :: String
8884
defaultRepo = "git://github.com/fujimura/hi-hspec.git"

src/Hi/Template.hs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module Hi.Template
55
, untemplate
66
) where
77

8-
import Control.Exception (bracket_)
98
import Hi.Directory (inTemporaryDirectory)
109
import qualified Hi.Git as Git
1110
import Hi.Types
@@ -16,48 +15,15 @@ import qualified Data.ByteString as BS (readFile)
1615
import Data.List (isSuffixOf)
1716
import Data.List.Split (splitOn)
1817

19-
import Paths_hi (getDataDir)
20-
import System.Directory
21-
import System.FilePath
22-
2318
-- | Read templates in given 'FilePath'
2419
readTemplates :: TemplateSource -> IO Files
25-
readTemplates BuiltInHSpec = readBuiltInTemplate "hspec"
26-
readTemplates BuiltInFlat = readBuiltInTemplate "flat"
2720
readTemplates (FromRepo repo) =
2821
inTemporaryDirectory "hi" $ do
2922
-- TODO Handle error
3023
_ <- Git.clone $ Git.expandUrl repo
3124
paths <- Git.lsFiles
3225
mapM fetchFile paths
3326

34-
readBuiltInTemplate :: String -> IO Files
35-
readBuiltInTemplate dir = do
36-
root <- getDataDir
37-
inDirectory (root </> "templates" </> dir) $ do
38-
paths <- getDirectoryContentsRecursively "./"
39-
mapM fetchFile paths
40-
41-
inDirectory :: FilePath -> IO a -> IO a
42-
inDirectory path action = do
43-
pwd <- getCurrentDirectory
44-
let go = setCurrentDirectory path
45-
back = setCurrentDirectory pwd
46-
bracket_ go back action
47-
48-
getDirectoryContentsRecursively :: FilePath -> IO [FilePath]
49-
getDirectoryContentsRecursively path = go [path]
50-
where
51-
go :: [FilePath] -> IO [FilePath]
52-
go [] = return []
53-
go (x:xs) = do
54-
isDir <- doesDirectoryExist x
55-
if isDir then do
56-
xs' <- filter (/= "..") <$> filter (/= ".") <$> getDirectoryContents x
57-
go (xs ++ map (x </>) xs')
58-
else
59-
(x:) <$> go xs
60-
6127
fetchFile :: FilePath -> IO File
6228
fetchFile fp | isTemplate fp = TemplateFile fp <$> BS.readFile fp
6329
| otherwise = RegularFile fp <$> BS.readFile fp

src/Hi/Types.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Data.ByteString (ByteString)
1212
data File = TemplateFile { getFilePath :: FilePath, getFileContents :: ByteString } |
1313
RegularFile { getFilePath :: FilePath, getFileContents :: ByteString } deriving (Show)
1414

15-
data TemplateSource = FromRepo String | BuiltInHSpec | BuiltInFlat deriving (Eq,Ord,Show)
15+
data TemplateSource = FromRepo String deriving (Eq,Ord,Show)
1616

1717
type Files = [File]
1818

templates/flat/.gitignore.template

Lines changed: 0 additions & 10 deletions
This file was deleted.

templates/flat/LICENSE.template

Lines changed: 0 additions & 30 deletions
This file was deleted.

templates/flat/Main.hs.template

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)