fixed the pb with dir creation

This commit is contained in:
Yann Esposito (Yogsototh) 2013-11-20 13:23:51 +01:00
parent 910e8b0189
commit bae928835a
7 changed files with 136 additions and 30 deletions

View file

@ -38,6 +38,8 @@ executable holy-project
, bytestring
, syb
, directory
, time
, filepath
-- from Tasty cabal with ansi-terminal
cpp-options: -DCOLORS
hs-source-dirs: src

View file

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2013 {{author}}
Copyright (c) {{year}} {{author}}
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View file

@ -2,20 +2,24 @@
module Main where
-- Project name manipulation
import Data.Char (toUpper,toLower,isLetter,isNumber)
import Data.List (intersperse)
import Data.Char (toUpper,toLower,isLetter,isNumber)
import Data.List (intersperse)
import Data.List.Split
-- Get current year for the License
import Data.Time.Clock
import Data.Time.Calendar
-- Console read write with colors
import System.Console.ANSI
import System.IO (hFlush, stdout)
import System.IO (hFlush, stdout)
-- Hastache
import Control.Applicative
import Data.Data
import Text.Hastache
import Text.Hastache.Context
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy.Char8 as LZ
-- File and directory Handling
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy.Char8 as LZ
import System.Directory
import System.FilePath.Posix (takeDirectory,(</>))
-- Get external file of package
import Paths_holy_project
@ -24,10 +28,11 @@ import Paths_holy_project
data Project = Project {
projectName :: String
, moduleName :: String
, author :: Maybe String
, mail :: Maybe String
, ghaccount :: Maybe String
, synopsis :: Maybe String } deriving (Data, Typeable)
, author :: String
, mail :: String
, ghaccount :: String
, synopsis :: String
, year :: String } deriving (Data, Typeable)
ioassert :: Bool -> String -> IO ()
ioassert True _ = return ()
@ -44,17 +49,19 @@ main = do
modulename = capitalize project
putStrLn $ "Project: " ++ projectname
putStrLn $ "Module: " ++ modulename
author <- ask "name"
email <- ask "email"
ghaccount <- ask "github account"
synopsis <- ask "project in less than a dozen word?"
createProject $ Project projectname modulename
(toJust author) (toJust email)
(toJust ghaccount) (toJust synopsis)
in_author <- ask "name"
in_email <- ask "email"
in_ghaccount <- ask "github account"
in_synopsis <- ask "project in less than a dozen word?"
current_year <- getCurrentYear
createProject $ Project projectname modulename in_author in_email
in_ghaccount in_synopsis current_year
end
where
toJust [] = Nothing
toJust str = Just str
getCurrentYear :: IO String
getCurrentYear = do
(current_year,_,_) <- getCurrentTime >>= return . toGregorian . utctDay
return (show current_year)
-- | bridgekeeper speak
bk :: String -> IO ()
@ -125,12 +132,13 @@ capitalize str = concat (map capitalizeWord (splitOneOf " -" str))
capitalizeWord _ = []
genFile :: MuContext IO -> [Char] -> [Char] -> IO ()
genFile :: MuContext IO -> FilePath -> FilePath -> IO ()
genFile context filename outputFileName = do
putStrLn $ '\t':outputFileName
pkgfileName <- getDataFileName ("scaffold/"++filename)
pkgfileName <- getDataFileName ("scaffold" </> filename)
template <- BS.readFile pkgfileName
transformedFile <- hastacheStr defaultConfig template context
createDirectoryIfMissing True (takeDirectory outputFileName)
LZ.writeFile outputFileName transformedFile
createProject :: Project -> IO ()
@ -143,10 +151,10 @@ createProject p = do
genFile context "LICENSE" $ "LICENSE"
genFile context "Setup.hs" $ "Setup.hs"
genFile context "project.cabal" $ (projectName p) ++ ".cabal"
genFile context "src/Main.hs" $ "src/Main.hs"
genFile context "src/ModuleName.hs" $ "src/"++(moduleName p)++".hs"
genFile context "src/ModuleName/Coconut.hs" $ "src/"++(moduleName p)++"/Coconut.hs"
genFile context "src/ModuleName/Swallow.hs" $ "src/"++(moduleName p)++"/Swallow.hs"
genFile context "test/ModuleName/Coconut/Test.hs" $ "test/"++(moduleName p)++"/Coconut/Test.hs"
genFile context "test/ModuleName/Swallow/Test.hs" $ "test/"++(moduleName p)++"/Swallow/Test.hs"
genFile context "test/Test.hs" $ "test/Test.hs"
genFile context ("src" </> "Main.hs" ) $ "src" </> "Main.hs"
genFile context ("src" </> "ModuleName.hs" ) $ "src" </> ((moduleName p)++".hs")
genFile context ("src" </> "ModuleName/Coconut.hs" ) $ "src" </> (moduleName p) </> "Coconut.hs"
genFile context ("src" </> "ModuleName/Swallow.hs" ) $ "src" </> (moduleName p) </> "Swallow.hs"
genFile context ("test" </> "ModuleName/Coconut/Test.hs") $ "test" </> (moduleName p) </> "Coconut" </> "Test.hs"
genFile context ("test" </> "ModuleName/Swallow/Test.hs") $ "test" </> (moduleName p) </> "Swallow" </> "Test.hs"
genFile context ("test" </> "Test.hs" ) $ "test" </> "Test.hs"

6
testing/.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
.cabal-sandbox
cabal.sandbox.config
dist
*.swp
*~
.ghci

21
testing/LICENSE Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2013 yname
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

2
testing/Setup.hs Normal file
View file

@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain

67
testing/testing.cabal Normal file
View file

@ -0,0 +1,67 @@
-- Initial project.cabal generated by holy-project.
-- For further documentation, see http://haskell.org/cabal/users-guide/
name: project
version: 0.1.0.0
synopsis: ysynops
-- description:
homepage: http://github.com/ygh/project
license: MIT
license-file: LICENSE
author: yname
maintainer: ymail
-- copyright:
category: Unknown
build-type: Simple
-- extra-source-files:
cabal-version: >=1.10
executable project
main-is: Main.hs
-- other-modules:
-- other-extensions:
build-depends: base >=4.6 && <4.7
hs-source-dirs: src
ghc-options: -Wall
default-language: Haskell2010
library
exposed-modules: Project
, Project.Swallow
, Project.Coconut
-- other-modules:
-- other-extensions:
build-depends: base >=4.6 && <4.7
ghc-options: -Wall
hs-source-dirs: src
default-language: Haskell2010
executable test-project
hs-source-dirs: test
ghc-options: -Wall
main-is: Test.hs
default-language: Haskell2010
build-depends: base ==4.6.*, Cabal >= 1.16.0
, project
, HUnit
, QuickCheck
, smallcheck
, tasty
, tasty-hunit
, tasty-quickcheck
, tasty-smallcheck
test-suite Tests
hs-source-dirs: test
ghc-options: -Wall
main-is: Test.hs
Type: exitcode-stdio-1.0
default-language: Haskell2010
build-depends: base ==4.6.*, Cabal >= 1.16.0
, project
, HUnit
, QuickCheck
, smallcheck
, tasty
, tasty-hunit
, tasty-quickcheck
, tasty-smallcheck