diff --git a/yesod/Scaffold/Build.hs b/yesod/Build.hs similarity index 99% rename from yesod/Scaffold/Build.hs rename to yesod/Build.hs index 69a54b97..86829ca4 100644 --- a/yesod/Scaffold/Build.hs +++ b/yesod/Build.hs @@ -1,5 +1,5 @@ {-# LANGUAGE OverloadedStrings #-} -module Scaffold.Build +module Build ( touch , getDeps , touchDeps diff --git a/yesod/Scaffold/Devel.hs b/yesod/Devel.hs similarity index 98% rename from yesod/Scaffold/Devel.hs rename to yesod/Devel.hs index ae5e06a4..4a19652e 100644 --- a/yesod/Scaffold/Devel.hs +++ b/yesod/Devel.hs @@ -1,5 +1,5 @@ {-# LANGUAGE OverloadedStrings #-} -module Scaffold.Devel +module Devel ( devel ) where @@ -13,7 +13,7 @@ import Distribution.Verbosity (normal) import Distribution.PackageDescription.Parse (readPackageDescription, readHookedBuildInfo) import Distribution.PackageDescription (emptyHookedBuildInfo) -- import Distribution.Simple.LocalBuildInfo (localPkgDescr) -import Scaffold.Build (getDeps, touchDeps, findHaskellFiles) +import Build (getDeps, touchDeps, findHaskellFiles) -- import Network.Wai.Handler.Warp (run) -- import Network.Wai.Middleware.Debug (debug) -- import Distribution.Text (display) diff --git a/yesod/CodeGen.hs b/yesod/Scaffolding/CodeGen.hs similarity index 96% rename from yesod/CodeGen.hs rename to yesod/Scaffolding/CodeGen.hs index 878159ad..de54d98f 100644 --- a/yesod/CodeGen.hs +++ b/yesod/Scaffolding/CodeGen.hs @@ -1,7 +1,7 @@ {-# LANGUAGE TemplateHaskell #-} -- | A code generation template haskell. Everything is taken as literal text, -- with ~var~ variable interpolation. -module CodeGen (codegen, codegenDir) where +module Scaffolding.CodeGen (codegen, codegenDir) where import Language.Haskell.TH.Syntax import Text.ParserCombinators.Parsec diff --git a/yesod/scaffold.hs b/yesod/Scaffolding/Scaffolder.hs similarity index 82% rename from yesod/scaffold.hs rename to yesod/Scaffolding/Scaffolder.hs index af56f7cb..3d2c5de8 100644 --- a/yesod/scaffold.hs +++ b/yesod/Scaffolding/Scaffolder.hs @@ -1,31 +1,20 @@ {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE CPP #-} -import CodeGen -import System.IO -import System.Directory -import qualified Data.ByteString.Char8 as S +module Scaffolding.Scaffolder (scaffold) where + +import Scaffolding.CodeGen + import Language.Haskell.TH.Syntax -import Data.Time (getCurrentTime, utctDay, toGregorian) -import Data.Char (toLower) -import Control.Applicative ((<$>)) -import qualified Data.ByteString.Lazy as L +import Control.Monad (unless) import qualified Data.Text.Lazy as LT import qualified Data.Text.Lazy.Encoding as LT -import Control.Monad (unless) -import System.Environment (getArgs) -import System.Exit (exitWith) - -import Scaffold.Build (touch) -import Scaffold.Devel (devel) - -import System.Process (rawSystem) - -qq :: String -#if __GLASGOW_HASKELL__ >= 700 -qq = "" -#else -qq = "$" -#endif +import qualified Data.ByteString.Lazy as L +import Control.Applicative ((<$>)) +import qualified Data.ByteString.Char8 as S +import Data.Time (getCurrentTime, utctDay, toGregorian) +import Data.Char (toLower) +import System.Directory +import System.IO prompt :: (String -> Bool) -> IO String prompt f = do @@ -36,42 +25,23 @@ prompt f = do putStrLn "That was not a valid entry, please try again: " prompt f -main :: IO () -main = do - args' <- getArgs - let (isDev, args) = - case args' of - "--dev":rest -> (True, rest) - _ -> (False, args') - let cmd = if isDev then "cabal-dev" else "cabal" - let cabal rest = rawSystem cmd rest >> return () - let build rest = rawSystem cmd $ "build":rest - case args of - ["init"] -> scaffold - "build":rest -> touch >> build rest >>= exitWith - ["touch"] -> touch - ["devel"] -> devel cabal - ["version"] -> putStrLn "0.9" - "configure":rest -> rawSystem cmd ("configure":rest) >>= exitWith - _ -> do - putStrLn "Usage: yesod " - putStrLn "Available commands:" - putStrLn " init Scaffold a new site" - putStrLn " configure Configure a project for building" - putStrLn " build Build project (performs TH dependency analysis)" - putStrLn " touch Touch any files with altered TH dependencies but do not build" - putStrLn " devel Run project with the devel server" - putStrLn " version Print the version of Yesod" - -puts :: String -> IO () -puts s = putStr s >> hFlush stdout +qq :: String +#if __GLASGOW_HASKELL__ >= 700 +qq = "" +#else +qq = "$" +#endif data Backend = Sqlite | Postgresql | MongoDB | Tiny deriving (Eq, Read, Show, Enum, Bounded) +puts :: String -> IO () +puts s = putStr s >> hFlush stdout + backends :: [Backend] backends = [minBound .. maxBound] + scaffold :: IO () scaffold = do puts $(codegenDir "input" "welcome") diff --git a/yesod/main.hs b/yesod/main.hs new file mode 100644 index 00000000..0c6f19b9 --- /dev/null +++ b/yesod/main.hs @@ -0,0 +1,35 @@ +import Scaffolding.Scaffolder +import System.Environment (getArgs) +import System.Exit (exitWith) + +import Build (touch) +import Devel (devel) + +import System.Process (rawSystem) + +main :: IO () +main = do + args' <- getArgs + let (isDev, args) = + case args' of + "--dev":rest -> (True, rest) + _ -> (False, args') + let cmd = if isDev then "cabal-dev" else "cabal" + let cabal rest = rawSystem cmd rest >> return () + let build rest = rawSystem cmd $ "build":rest + case args of + ["init"] -> scaffold + "build":rest -> touch >> build rest >>= exitWith + ["touch"] -> touch + ["devel"] -> devel cabal + ["version"] -> putStrLn "0.9" + "configure":rest -> rawSystem cmd ("configure":rest) >>= exitWith + _ -> do + putStrLn "Usage: yesod " + putStrLn "Available commands:" + putStrLn " init Scaffold a new site" + putStrLn " configure Configure a project for building" + putStrLn " build Build project (performs TH dependency analysis)" + putStrLn " touch Touch any files with altered TH dependencies but do not build" + putStrLn " devel Run project with the devel server" + putStrLn " version Print the version of Yesod" diff --git a/yesod/test/runscaffold.sh b/yesod/test/runscaffold.sh index 03b40ced..34798202 100755 --- a/yesod/test/runscaffold.sh +++ b/yesod/test/runscaffold.sh @@ -1,3 +1,3 @@ #!/bin/bash -x -rm -rf foobar && runghc scaffold.hs init && cd foobar && cabal install && cabal install -fdevel && cd .. +rm -rf foobar && runghc main.hs init && cd foobar && cabal install && cabal install -fdevel && cd .. diff --git a/yesod/test/scaffold.shelltest b/yesod/test/scaffold.shelltest index 85be8700..90d73411 100644 --- a/yesod/test/scaffold.shelltest +++ b/yesod/test/scaffold.shelltest @@ -1,6 +1,6 @@ # Important! run with test/run.sh -rm -rf foobar && runghc scaffold.hs init && cd foobar && cabal install && cabal install -fdevel && cd .. +rm -rf foobar && runghc main.hs init && cd foobar && cabal install && cabal install -fdevel && cd .. <<< Michael foobar @@ -10,7 +10,7 @@ t >>> /.*Registering foobar-0.0.0.*/ >>>= 0 -rm -rf foobar && runghc scaffold.hs init && cd foobar && cabal install && cabal install -fdevel && cd .. +rm -rf foobar && runghc main.hs init && cd foobar && cabal install && cabal install -fdevel && cd .. <<< Michael foobar @@ -20,7 +20,7 @@ s >>> /.*Registering foobar-0.0.0.*/ >>>= 0 -rm -rf foobar && runghc scaffold.hs init && cd foobar && cabal install && cabal install -fdevel && cd .. && rm -rf foobar +rm -rf foobar && runghc main.hs init && cd foobar && cabal install && cabal install -fdevel && cd .. && rm -rf foobar <<< Michael foobar diff --git a/yesod/yesod.cabal b/yesod/yesod.cabal index 1a7d8387..b3576e30 100644 --- a/yesod/yesod.cabal +++ b/yesod/yesod.cabal @@ -99,10 +99,11 @@ executable yesod , blaze-builder >= 0.2 && < 0.4 , process ghc-options: -Wall -threaded - main-is: scaffold.hs - other-modules: CodeGen - Scaffold.Build - Scaffold.Devel + main-is: main.hs + other-modules: Scaffolding.CodeGen + Scaffolding.Scaffolder + Devel + Build source-repository head type: git