diff --git a/Scaffold/Build.hs b/Scaffold/Build.hs index d193440a..3660fb63 100644 --- a/Scaffold/Build.hs +++ b/Scaffold/Build.hs @@ -6,6 +6,8 @@ module Scaffold.Build , findHaskellFiles ) where +-- FIXME there's a bug when getFileStatus applies to a file temporary deleted (e.g., Vim saving a file) + import qualified Distribution.Simple.Build as B import System.Directory (getDirectoryContents, doesDirectoryExist) import Data.List (isSuffixOf) diff --git a/full-test.sh b/full-test.sh index 809d00cb..e3207151 100755 --- a/full-test.sh +++ b/full-test.sh @@ -1,7 +1,6 @@ #!/bin/sh cabal clean && cabal install && rm -rf foobar && \ - runghc scaffold.hs < input-sqlite && cd foobar && cabal install && cd .. && \ - runghc scaffold.hs < input-postgres && cd foobar && cabal install && cd .. && \ - runghc scaffold.hs < input-mini && cd foobar && cabal install && cd .. && \ - rm -rf foobar + runghc scaffold.hs init < input-sqlite && cd foobar && cabal install && cabal install -fdevel && cd .. && rm -rf foobar && \ + runghc scaffold.hs init < input-postgres && cd foobar && cabal install && cabal install -fdevel && cd .. && rm -rf foobar && \ + runghc scaffold.hs init < input-mini && cd foobar && cabal install && cabal install -fdevel && cd .. && rm -rf foobar diff --git a/scaffold.hs b/scaffold.hs index 1ce4a593..d7097e1c 100644 --- a/scaffold.hs +++ b/scaffold.hs @@ -44,6 +44,7 @@ main = do putStrLn "Available commands:" putStrLn " init Scaffold a new site" putStrLn " build Build project (performs TH dependency analysis)" + putStrLn " devel Run project with the devel server" scaffold :: IO () scaffold = do @@ -100,8 +101,7 @@ scaffold = do mkDir "julius" mkDir "static" - writeFile' "test.hs" $(codegen "test_hs") - writeFile' "production.hs" $(codegen "production_hs") + writeFile' (project ++ ".hs") $(codegen "test_hs") writeFile' "devel-server.hs" $(codegen "devel-server_hs") writeFile' (project ++ ".cabal") $ if backendS == "m" then $(codegen "mini-cabal") else $(codegen "cabal") writeFile' "LICENSE" $(codegen "LICENSE") diff --git a/scaffold/Controller_hs.cg b/scaffold/Controller_hs.cg index 8aafe2b2..726a2309 100644 --- a/scaffold/Controller_hs.cg +++ b/scaffold/Controller_hs.cg @@ -4,6 +4,7 @@ {-# OPTIONS_GHC -fno-warn-orphans #-} module Controller ( with~sitearg~ + , withDevelApp ) where import ~sitearg~ @@ -12,6 +13,7 @@ import Yesod.Helpers.Static import Yesod.Helpers.Auth import Database.Persist.GenericSql import Data.ByteString (ByteString) +import Data.Dynamic (Dynamic, toDyn) -- Import all relevant handler modules here. import Handler.Root @@ -41,3 +43,6 @@ with~sitearg~ f = Settings.withConnectionPool $ \p -> do where s = static Settings.staticdir +withDevelApp :: Dynamic +withDevelApp = toDyn (with~sitearg~ :: (Application -> IO ()) -> IO ()) + diff --git a/scaffold/cabal.cg b/scaffold/cabal.cg index 88382fcc..83474931 100644 --- a/scaffold/cabal.cg +++ b/scaffold/cabal.cg @@ -16,10 +16,34 @@ Flag production Description: Build the production executable. Default: False -executable ~project~-test - if flag(production) +Flag devel + Description: Build for use with "yesod devel" + Default: False + +library + if flag(devel) + Buildable: True + else Buildable: False - main-is: test.hs + exposed-modules: Controller + other-modules: ~sitearg~ + Model + Settings + StaticFiles + Handler.Root + +executable ~project~ + if flag(devel) + Buildable: False + + if flag(production) + cpp-options: -DPRODUCTION + ghc-options: -Wall -threaded -O2 + else + ghc-options: -Wall -threaded + + main-is: ~project~.hs + build-depends: base >= 4 && < 5 , yesod >= 0.8 && < 0.9 , yesod-auth @@ -39,20 +63,4 @@ executable ~project~-test , transformers , warp , blaze-builder - ghc-options: -Wall -threaded - -executable ~project~-production - if flag(production) - Buildable: True - else - Buildable: False - cpp-options: -DPRODUCTION - main-is: production.hs - ghc-options: -Wall -threaded - -executable ~project~-devel - if flag(production) - Buildable: False - main-is: devel-server.hs - ghc-options: -Wall -O2 -threaded diff --git a/scaffold/mini-Controller_hs.cg b/scaffold/mini-Controller_hs.cg index 3711043c..b207c5dc 100644 --- a/scaffold/mini-Controller_hs.cg +++ b/scaffold/mini-Controller_hs.cg @@ -4,6 +4,7 @@ {-# OPTIONS_GHC -fno-warn-orphans #-} module Controller ( with~sitearg~ + , withDevelApp ) where import ~sitearg~ @@ -11,6 +12,7 @@ import Settings import Yesod.Helpers.Static import Data.ByteString (ByteString) import Network.Wai (Application) +import Data.Dynamic (Dynamic, toDyn) -- Import all relevant handler modules here. import Handler.Root @@ -38,3 +40,7 @@ with~sitearg~ f = do toWaiApp h >>= f where s = static Settings.staticdir + +withDevelApp :: Dynamic +withDevelApp = toDyn (with~sitearg~ :: (Application -> IO ()) -> IO ()) + diff --git a/scaffold/mini-cabal.cg b/scaffold/mini-cabal.cg index 6d253ba7..7e48ea42 100644 --- a/scaffold/mini-cabal.cg +++ b/scaffold/mini-cabal.cg @@ -16,10 +16,33 @@ Flag production Description: Build the production executable. Default: False -executable ~project~-test - if flag(production) +Flag devel + Description: Build for use with "yesod devel" + Default: False + +library + if flag(devel) + Buildable: True + else Buildable: False - main-is: test.hs + exposed-modules: Controller + other-modules: ~sitearg~ + Settings + StaticFiles + Handler.Root + +executable ~project~ + if flag(devel) + Buildable: False + + if flag(production) + cpp-options: -DPRODUCTION + ghc-options: -Wall -threaded -O2 + else + ghc-options: -Wall -threaded + + main-is: ~project~.hs + build-depends: base >= 4 && < 5 , yesod-core >= 0.8 && < 0.9 , yesod-static @@ -36,17 +59,3 @@ executable ~project~-test , blaze-builder ghc-options: -Wall -threaded -executable ~project~-production - if flag(production) - Buildable: True - else - Buildable: False - cpp-options: -DPRODUCTION - main-is: production.hs - ghc-options: -Wall -threaded - -executable ~project~-devel - if flag(production) - Buildable: False - main-is: devel-server.hs - ghc-options: -Wall -O2 -threaded diff --git a/scaffold/production_hs.cg b/scaffold/production_hs.cg deleted file mode 100644 index 3ca59728..00000000 --- a/scaffold/production_hs.cg +++ /dev/null @@ -1,6 +0,0 @@ -import Controller (with~sitearg~) -import Network.Wai.Handler.Warp (run) - -main :: IO () -main = with~sitearg~ $ run 3000 - diff --git a/scaffold/test_hs.cg b/scaffold/test_hs.cg index 5b0089f9..35527958 100644 --- a/scaffold/test_hs.cg +++ b/scaffold/test_hs.cg @@ -1,3 +1,11 @@ +{-# LANGUAGE CPP #-} +#if PRODUCTION +import Controller (with~sitearg~) +import Network.Wai.Handler.Warp (run) + +main :: IO () +main = with~sitearg~ $ run 3000 +#else import Controller (with~sitearg~) import System.IO (hPutStrLn, stderr) import Network.Wai.Middleware.Debug (debug) @@ -8,4 +16,5 @@ main = do let port = 3000 hPutStrLn stderr $ "Application launched, listening on port " ++ show port with~sitearg~ $ run port . debug +#endif