creation of file ok, now, just have to create them
This commit is contained in:
parent
a2a3f05189
commit
1d1f33c2ba
5 changed files with 82 additions and 5 deletions
6
a-simple-test/.gitignore
vendored
Normal file
6
a-simple-test/.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
.cabal-sandbox
|
||||||
|
cabal.sandbox.config
|
||||||
|
dist
|
||||||
|
*.swp
|
||||||
|
*~
|
||||||
|
.ghci
|
21
a-simple-test/LICENSE
Normal file
21
a-simple-test/LICENSE
Normal 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.
|
|
@ -14,7 +14,8 @@ maintainer: Yann.Esposito@gmail.com
|
||||||
category: Unknown
|
category: Unknown
|
||||||
build-type: Simple
|
build-type: Simple
|
||||||
-- extra-source-files:
|
-- extra-source-files:
|
||||||
data-files: scaffold/gitignore
|
data-files: scaffold/gitignore
|
||||||
|
, scaffold/LICENSE
|
||||||
cabal-version: >=1.10
|
cabal-version: >=1.10
|
||||||
|
|
||||||
executable holy-project
|
executable holy-project
|
||||||
|
@ -24,6 +25,10 @@ executable holy-project
|
||||||
build-depends: base >=4.6 && <4.7
|
build-depends: base >=4.6 && <4.7
|
||||||
, ansi-terminal
|
, ansi-terminal
|
||||||
, split
|
, split
|
||||||
|
, hastache
|
||||||
|
, bytestring
|
||||||
|
, syb
|
||||||
|
, directory
|
||||||
-- from Tasty cabal with ansi-terminal
|
-- from Tasty cabal with ansi-terminal
|
||||||
cpp-options: -DCOLORS
|
cpp-options: -DCOLORS
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
|
|
21
scaffold/LICENSE
Normal file
21
scaffold/LICENSE
Normal 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.
|
32
src/Main.hs
32
src/Main.hs
|
@ -1,10 +1,23 @@
|
||||||
|
{-# LANGUAGE DeriveDataTypeable #-}
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
|
-- Project name manipulation
|
||||||
import Data.Char (toUpper,toLower,isLetter,isNumber)
|
import Data.Char (toUpper,toLower,isLetter,isNumber)
|
||||||
import Data.List (intersperse)
|
import Data.List (intersperse)
|
||||||
import Data.List.Split
|
import Data.List.Split
|
||||||
|
-- Console read write with colors
|
||||||
import System.Console.ANSI
|
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
|
||||||
|
import System.Directory
|
||||||
|
|
||||||
|
-- Get external file of package
|
||||||
import Paths_holy_project
|
import Paths_holy_project
|
||||||
|
|
||||||
-- | Record containing all information to initialize a project
|
-- | Record containing all information to initialize a project
|
||||||
|
@ -14,7 +27,7 @@ data Project = Project {
|
||||||
, author :: Maybe String
|
, author :: Maybe String
|
||||||
, mail :: Maybe String
|
, mail :: Maybe String
|
||||||
, ghaccount :: Maybe String
|
, ghaccount :: Maybe String
|
||||||
, synopsis :: Maybe String }
|
, synopsis :: Maybe String } deriving (Data, Typeable)
|
||||||
|
|
||||||
ioassert :: Bool -> String -> IO ()
|
ioassert :: Bool -> String -> IO ()
|
||||||
ioassert True _ = return ()
|
ioassert True _ = return ()
|
||||||
|
@ -96,7 +109,8 @@ ask info = do
|
||||||
|
|
||||||
-- | verify if project is conform
|
-- | verify if project is conform
|
||||||
checkProjectName :: String -> Bool
|
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"
|
-- | transform a chain like "Holy project" in "holy-project"
|
||||||
projectNameFromString :: String -> String
|
projectNameFromString :: String -> String
|
||||||
|
@ -111,8 +125,18 @@ capitalize str = concat (map capitalizeWord (splitOneOf " -" str))
|
||||||
capitalizeWord _ = []
|
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 :: Project -> IO ()
|
||||||
createProject p = do
|
createProject p = do
|
||||||
|
let context = mkGenericContext p
|
||||||
|
createDirectory (projectName p)
|
||||||
|
setCurrentDirectory (projectName p)
|
||||||
putStrLn "I'm not a witch, I'm not a witch!"
|
putStrLn "I'm not a witch, I'm not a witch!"
|
||||||
filepath <- getDataFileName "scaffold/gitignore"
|
genFile context "scaffold/gitignore" ".gitignore"
|
||||||
putStrLn filepath
|
genFile context "scaffold/LICENSE" "LICENSE"
|
||||||
|
|
Loading…
Reference in a new issue