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
) 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)

View File

@ -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

View File

@ -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")

View File

@ -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 ())

View File

@ -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

View File

@ -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 ())

View File

@ -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

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 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