Scaffolded site uses yesod devel properly

This commit is contained in:
Michael Snoyman 2011-04-18 17:28:34 +03:00
parent c55a122236
commit 1aec06f73d
9 changed files with 80 additions and 48 deletions

View File

@ -6,6 +6,8 @@ module Scaffold.Build
, findHaskellFiles , findHaskellFiles
) where ) 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 qualified Distribution.Simple.Build as B
import System.Directory (getDirectoryContents, doesDirectoryExist) import System.Directory (getDirectoryContents, doesDirectoryExist)
import Data.List (isSuffixOf) import Data.List (isSuffixOf)

View File

@ -1,7 +1,6 @@
#!/bin/sh #!/bin/sh
cabal clean && cabal install && rm -rf foobar && \ cabal clean && cabal install && rm -rf foobar && \
runghc scaffold.hs < input-sqlite && cd foobar && cabal install && cd .. && \ runghc scaffold.hs init < input-sqlite && cd foobar && cabal install && cabal install -fdevel && cd .. && rm -rf foobar && \
runghc scaffold.hs < input-postgres && cd foobar && cabal install && cd .. && \ runghc scaffold.hs init < input-postgres && cd foobar && cabal install && cabal install -fdevel && cd .. && rm -rf foobar && \
runghc scaffold.hs < input-mini && cd foobar && cabal install && cd .. && \ runghc scaffold.hs init < input-mini && cd foobar && cabal install && cabal install -fdevel && cd .. && rm -rf foobar
rm -rf foobar

View File

@ -44,6 +44,7 @@ main = do
putStrLn "Available commands:" putStrLn "Available commands:"
putStrLn " init Scaffold a new site" putStrLn " init Scaffold a new site"
putStrLn " build Build project (performs TH dependency analysis)" putStrLn " build Build project (performs TH dependency analysis)"
putStrLn " devel Run project with the devel server"
scaffold :: IO () scaffold :: IO ()
scaffold = do scaffold = do
@ -100,8 +101,7 @@ scaffold = do
mkDir "julius" mkDir "julius"
mkDir "static" mkDir "static"
writeFile' "test.hs" $(codegen "test_hs") writeFile' (project ++ ".hs") $(codegen "test_hs")
writeFile' "production.hs" $(codegen "production_hs")
writeFile' "devel-server.hs" $(codegen "devel-server_hs") writeFile' "devel-server.hs" $(codegen "devel-server_hs")
writeFile' (project ++ ".cabal") $ if backendS == "m" then $(codegen "mini-cabal") else $(codegen "cabal") writeFile' (project ++ ".cabal") $ if backendS == "m" then $(codegen "mini-cabal") else $(codegen "cabal")
writeFile' "LICENSE" $(codegen "LICENSE") writeFile' "LICENSE" $(codegen "LICENSE")

View File

@ -4,6 +4,7 @@
{-# OPTIONS_GHC -fno-warn-orphans #-} {-# OPTIONS_GHC -fno-warn-orphans #-}
module Controller module Controller
( with~sitearg~ ( with~sitearg~
, withDevelApp
) where ) where
import ~sitearg~ import ~sitearg~
@ -12,6 +13,7 @@ import Yesod.Helpers.Static
import Yesod.Helpers.Auth import Yesod.Helpers.Auth
import Database.Persist.GenericSql import Database.Persist.GenericSql
import Data.ByteString (ByteString) import Data.ByteString (ByteString)
import Data.Dynamic (Dynamic, toDyn)
-- Import all relevant handler modules here. -- Import all relevant handler modules here.
import Handler.Root import Handler.Root
@ -41,3 +43,6 @@ with~sitearg~ f = Settings.withConnectionPool $ \p -> do
where where
s = static Settings.staticdir s = static Settings.staticdir
withDevelApp :: Dynamic
withDevelApp = toDyn (with~sitearg~ :: (Application -> IO ()) -> IO ())

View File

@ -16,10 +16,34 @@ Flag production
Description: Build the production executable. Description: Build the production executable.
Default: False Default: False
executable ~project~-test Flag devel
if flag(production) Description: Build for use with "yesod devel"
Default: False
library
if flag(devel)
Buildable: True
else
Buildable: False 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 build-depends: base >= 4 && < 5
, yesod >= 0.8 && < 0.9 , yesod >= 0.8 && < 0.9
, yesod-auth , yesod-auth
@ -39,20 +63,4 @@ executable ~project~-test
, transformers , transformers
, warp , warp
, blaze-builder , 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

View File

@ -4,6 +4,7 @@
{-# OPTIONS_GHC -fno-warn-orphans #-} {-# OPTIONS_GHC -fno-warn-orphans #-}
module Controller module Controller
( with~sitearg~ ( with~sitearg~
, withDevelApp
) where ) where
import ~sitearg~ import ~sitearg~
@ -11,6 +12,7 @@ import Settings
import Yesod.Helpers.Static import Yesod.Helpers.Static
import Data.ByteString (ByteString) import Data.ByteString (ByteString)
import Network.Wai (Application) import Network.Wai (Application)
import Data.Dynamic (Dynamic, toDyn)
-- Import all relevant handler modules here. -- Import all relevant handler modules here.
import Handler.Root import Handler.Root
@ -38,3 +40,7 @@ with~sitearg~ f = do
toWaiApp h >>= f toWaiApp h >>= f
where where
s = static Settings.staticdir s = static Settings.staticdir
withDevelApp :: Dynamic
withDevelApp = toDyn (with~sitearg~ :: (Application -> IO ()) -> IO ())

View File

@ -16,10 +16,33 @@ Flag production
Description: Build the production executable. Description: Build the production executable.
Default: False Default: False
executable ~project~-test Flag devel
if flag(production) Description: Build for use with "yesod devel"
Default: False
library
if flag(devel)
Buildable: True
else
Buildable: False 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 build-depends: base >= 4 && < 5
, yesod-core >= 0.8 && < 0.9 , yesod-core >= 0.8 && < 0.9
, yesod-static , yesod-static
@ -36,17 +59,3 @@ executable ~project~-test
, blaze-builder , blaze-builder
ghc-options: -Wall -threaded 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

View File

@ -1,6 +0,0 @@
import Controller (with~sitearg~)
import Network.Wai.Handler.Warp (run)
main :: IO ()
main = with~sitearg~ $ run 3000

View File

@ -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 Controller (with~sitearg~)
import System.IO (hPutStrLn, stderr) import System.IO (hPutStrLn, stderr)
import Network.Wai.Middleware.Debug (debug) import Network.Wai.Middleware.Debug (debug)
@ -8,4 +16,5 @@ main = do
let port = 3000 let port = 3000
hPutStrLn stderr $ "Application launched, listening on port " ++ show port hPutStrLn stderr $ "Application launched, listening on port " ++ show port
with~sitearg~ $ run port . debug with~sitearg~ $ run port . debug
#endif