From bae928835a0186aaaa4242aa97fc4bc04a4c7379 Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Wed, 20 Nov 2013 13:23:51 +0100 Subject: [PATCH] fixed the pb with dir creation --- holy-project.cabal | 2 ++ scaffold/LICENSE | 2 +- src/Main.hs | 66 +++++++++++++++++++++++------------------- testing/.gitignore | 6 ++++ testing/LICENSE | 21 ++++++++++++++ testing/Setup.hs | 2 ++ testing/testing.cabal | 67 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 136 insertions(+), 30 deletions(-) create mode 100644 testing/.gitignore create mode 100644 testing/LICENSE create mode 100644 testing/Setup.hs create mode 100644 testing/testing.cabal diff --git a/holy-project.cabal b/holy-project.cabal index bc4a6ad..cab4a9a 100644 --- a/holy-project.cabal +++ b/holy-project.cabal @@ -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 diff --git a/scaffold/LICENSE b/scaffold/LICENSE index 2e4cf5c..c792716 100644 --- a/scaffold/LICENSE +++ b/scaffold/LICENSE @@ -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 diff --git a/src/Main.hs b/src/Main.hs index a560fb2..650ca05 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -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" diff --git a/testing/.gitignore b/testing/.gitignore new file mode 100644 index 0000000..3a124cb --- /dev/null +++ b/testing/.gitignore @@ -0,0 +1,6 @@ +.cabal-sandbox +cabal.sandbox.config +dist +*.swp +*~ +.ghci diff --git a/testing/LICENSE b/testing/LICENSE new file mode 100644 index 0000000..e75eef6 --- /dev/null +++ b/testing/LICENSE @@ -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. diff --git a/testing/Setup.hs b/testing/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/testing/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/testing/testing.cabal b/testing/testing.cabal new file mode 100644 index 0000000..1ef628a --- /dev/null +++ b/testing/testing.cabal @@ -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