creation of file ok, now, just have to create them

This commit is contained in:
Yann Esposito (Yogsototh) 2013-11-19 21:46:54 +01:00
parent a2a3f05189
commit 1d1f33c2ba
5 changed files with 82 additions and 5 deletions

6
a-simple-test/.gitignore vendored Normal file
View file

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

21
a-simple-test/LICENSE Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2013
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.

View file

@ -14,7 +14,8 @@ maintainer: Yann.Esposito@gmail.com
category: Unknown
build-type: Simple
-- extra-source-files:
data-files: scaffold/gitignore
data-files: scaffold/gitignore
, scaffold/LICENSE
cabal-version: >=1.10
executable holy-project
@ -24,6 +25,10 @@ executable holy-project
build-depends: base >=4.6 && <4.7
, ansi-terminal
, split
, hastache
, bytestring
, syb
, directory
-- from Tasty cabal with ansi-terminal
cpp-options: -DCOLORS
hs-source-dirs: src

21
scaffold/LICENSE Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2013 {{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
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.

View file

@ -1,10 +1,23 @@
{-# LANGUAGE DeriveDataTypeable #-}
module Main where
-- Project name manipulation
import Data.Char (toUpper,toLower,isLetter,isNumber)
import Data.List (intersperse)
import Data.List.Split
-- Console read write with colors
import System.Console.ANSI
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
import System.Directory
-- Get external file of package
import Paths_holy_project
-- | Record containing all information to initialize a project
@ -14,7 +27,7 @@ data Project = Project {
, author :: Maybe String
, mail :: Maybe String
, ghaccount :: Maybe String
, synopsis :: Maybe String }
, synopsis :: Maybe String } deriving (Data, Typeable)
ioassert :: Bool -> String -> IO ()
ioassert True _ = return ()
@ -96,7 +109,8 @@ ask info = do
-- | verify if project is conform
checkProjectName :: String -> Bool
checkProjectName = all (\c -> (isLetter c)||(isNumber c)||(c=='-')||(c==' '))
checkProjectName [] = False
checkProjectName str = all (\c -> (isLetter c)||(isNumber c)||(c=='-')||(c==' ')) str
-- | transform a chain like "Holy project" in "holy-project"
projectNameFromString :: String -> String
@ -111,8 +125,18 @@ capitalize str = concat (map capitalizeWord (splitOneOf " -" str))
capitalizeWord _ = []
genFile context filename outputFileName = do
putStrLn $ '\t':outputFileName
pkgfileName <- getDataFileName filename
template <- BS.readFile pkgfileName
transformedFile <- hastacheStr defaultConfig template context
LZ.writeFile outputFileName transformedFile
createProject :: Project -> IO ()
createProject p = do
let context = mkGenericContext p
createDirectory (projectName p)
setCurrentDirectory (projectName p)
putStrLn "I'm not a witch, I'm not a witch!"
filepath <- getDataFileName "scaffold/gitignore"
putStrLn filepath
genFile context "scaffold/gitignore" ".gitignore"
genFile context "scaffold/LICENSE" "LICENSE"