Skip to content

Commit

Permalink
Scaffolded site uses yesod devel properly
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Apr 18, 2011
1 parent c55a122 commit 1aec06f
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 48 deletions.
2 changes: 2 additions & 0 deletions Scaffold/Build.hs
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions 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
4 changes: 2 additions & 2 deletions scaffold.hs
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions scaffold/Controller_hs.cg
Expand Up @@ -4,6 +4,7 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Controller
( with~sitearg~
, withDevelApp
) where

import ~sitearg~
Expand All @@ -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
Expand Down Expand Up @@ -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 ())

46 changes: 27 additions & 19 deletions scaffold/cabal.cg
Expand Up @@ -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
Expand All @@ -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

6 changes: 6 additions & 0 deletions scaffold/mini-Controller_hs.cg
Expand Up @@ -4,13 +4,15 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Controller
( with~sitearg~
, withDevelApp
) where

import ~sitearg~
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
Expand Down Expand Up @@ -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 ())

43 changes: 26 additions & 17 deletions scaffold/mini-cabal.cg
Expand Up @@ -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
Expand All @@ -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
6 changes: 0 additions & 6 deletions scaffold/production_hs.cg

This file was deleted.

9 changes: 9 additions & 0 deletions 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)
Expand All @@ -8,4 +16,5 @@ main = do
let port = 3000
hPutStrLn stderr $ "Application launched, listening on port " ++ show port
with~sitearg~ $ run port . debug
#endif

0 comments on commit 1aec06f

Please sign in to comment.