Templates.hs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. {-# LANGUAGE RecordWildCards #-}
  2. {-# LANGUAGE OverloadedStrings #-}
  3. module Templates where
  4. import Data.Monoid ((<>))
  5. import qualified Data.Text as T
  6. import Lens.Family
  7. import Types
  8. cabalHeader :: ProjectDetails -> T.Text
  9. cabalHeader pr = T.unlines
  10. [ "name: " <> pr^.projectName
  11. , "version: 0.1.0.0"
  12. , case pr^.projectSynopsis of
  13. Just s -> "synopsis: " <> s
  14. Nothing -> "-- synopsis:"
  15. , case pr^.projectDescription of
  16. Just s -> "description: " <> s
  17. Nothing -> "-- description:"
  18. , case pr^.projectLicense of
  19. Nothing -> "license: BSD3"
  20. Just l -> "license: " <> l
  21. , "author: " <> pr^.projectAuthor <> " <" <> pr^.projectEmail <> ">"
  22. , "maintainer: " <> pr^.projectAuthor <> " <" <> pr^.projectEmail <> ">"
  23. , "copyright: @" <> pr^.projectYear <> " " <> pr^.projectAuthor
  24. , case pr^.projectCategory of
  25. Just c -> "category: " <> c
  26. Nothing -> "-- category:"
  27. , "build-type: Simple"
  28. , "cabal-version: >=1.14"
  29. ]
  30. cabalLibrary :: LibraryDetails -> T.Text
  31. cabalLibrary lib = T.unlines $
  32. [ "library"
  33. , " hs-source-dirs: src"
  34. , " ghc-options: -Wall"
  35. , " build-depends: base >=4.7 && <5"
  36. , " default-language: Haskell2010"
  37. , " default-extensions: ScopedTypeVariables"
  38. ] <> mods
  39. where
  40. mods = case lib^.libMods of
  41. [] -> []
  42. (x:xs) ->
  43. (" exposed-modules: " <> x) :
  44. [" , " <> m | m <- xs ]
  45. cabalExecutable :: ExecutableDetails -> T.Text
  46. cabalExecutable exe = T.unlines $
  47. [ "executable " <> exe^.execName
  48. , " hs-source-dirs: " <> exe^.execDir
  49. , " main-is: Main.hs"
  50. , " default-language: Haskell2010"
  51. , " default-extensions: ScopedTypeVariables"
  52. , " ghc-options: -Wall"
  53. ] <> deps
  54. where
  55. baseDep = " build-depends: base >=4.7 && <5"
  56. deps =
  57. baseDep : [ " , " <> m
  58. | m <- exe^.execDeps
  59. ]
  60. defaultBin :: T.Text
  61. defaultBin = T.unlines $
  62. [ "module Main where"
  63. , ""
  64. , "main :: IO ()"
  65. , "main = return ()"
  66. ]
  67. defaultLib :: T.Text -> T.Text
  68. defaultLib mod = T.unlines $
  69. [ "module " <> mod
  70. , "("
  71. , ") where"
  72. ]
  73. defaultTest :: T.Text -> T.Text
  74. defaultTest mod = T.unlines $
  75. [ "module " <> mod <> "(main) where" ]
  76. defaultGitignore :: T.Text
  77. defaultGitignore = T.unlines
  78. [ "dist"
  79. , "dist-*"
  80. , "*~"
  81. , "cabal-dev"
  82. , "*.o"
  83. , "*.hi"
  84. , "*.chi"
  85. , "*.chs.h"
  86. , "*.dyn_o"
  87. , "*.dyn_hi"
  88. , ".hpc"
  89. , ".hsenv"
  90. , ".cabal-sandbox/"
  91. , "cabal.sandbox.config"
  92. , "*.prof"
  93. , "*.aux"
  94. , "*.hp"
  95. , "*.eventlog"
  96. , "cabal.project.local"
  97. , ".ghc.environment.*"
  98. ]