on master help sign in
1. Added the WATCH_SERVER flag that is enabled by default

1. Added an argument to watch, --no-server which will disable the embedded server. 1. Added a deprecation message to the preview mode

commitf01b64164954603466f746cfc9412c7cfac3b443 authorEric Stolten <stoltene2@gmail.com> dateSun 25 Aug 2013, 22:49 (13 years ago) parentfbc43b3
3 files changed+61−30
hakyll.cabal+22 src/Hakyll/Commands.hs+21−18 src/Hakyll/Main.hs+18−12
hakyll.cabal+22
@@ -78,6 +78,10 @@ Flag previewServer
7878 Description: Include the preview server
7979 Default: True
8080
81+Flag watchServer
82+ Description: Include the watch server
83+ Default: True
84+
8185Flag checkExternal
8286 Description: Include external link checking
8387 Default: True
@@ -177,6 +181,15 @@ Library
177181 Hakyll.Preview.Poll
178182 Hakyll.Preview.Server
179183
184+ If flag(watchServer)
185+ Build-depends:
186+ fsnotify >= 0.0.6 && < 0.1,
187+ system-filepath >= 0.4.6 && <= 0.5
188+ Cpp-options:
189+ -DWATCH_SERVER
190+ Other-modules:
191+ Hakyll.Preview.Poll
192+
180193 If flag(checkExternal)
181194 Build-depends:
182195 http-conduit >= 1.8 && < 1.10,
@@ -254,6 +267,15 @@ Test-suite hakyll-tests
254267 Hakyll.Preview.Poll
255268 Hakyll.Preview.Server
256269
270+ If flag(watchServer)
271+ Build-depends:
272+ fsnotify >= 0.0.6 && < 0.1,
273+ system-filepath >= 0.4.6 && <= 0.5
274+ Cpp-options:
275+ -DWATCH_SERVER
276+ Other-modules:
277+ Hakyll.Preview.Poll
278+
257279 If flag(checkExternal)
258280 Build-depends:
259281 http-conduit >= 1.8 && < 1.10,
src/Hakyll/Commands.hs+21−18
@@ -28,8 +28,11 @@ import Hakyll.Core.Runtime
2828import Hakyll.Core.Util.File
2929
3030--------------------------------------------------------------------------------
31−#ifdef PREVIEW_SERVER
31+#ifdef WATCH_SERVER
3232import Hakyll.Preview.Poll (watchUpdates)
33+#endif
34+
35+#ifdef PREVIEW_SERVER
3336import Hakyll.Preview.Server
3437#endif
3538
@@ -62,8 +65,9 @@ clean conf = do
6265-- | Preview the site
6366preview :: Configuration -> Verbosity -> Rules a -> Int -> IO ()
6467#ifdef PREVIEW_SERVER
65−preview conf verbosity rules port = do
66− watch' conf verbosity rules (server conf port)
68+preview _ _ _ _ = mapM_ putStrLn [ "The preview command has been deprecated."
69+ , "Use the watch command for recompilation and serving."
70+ , "You can disable the server with watch --no-server"]
6771#else
6872preview _ _ _ _ = previewServerDisabled
6973#endif
@@ -71,31 +75,28 @@ preview _ _ _ _ = previewServerDisabled
7175
7276--------------------------------------------------------------------------------
7377-- | Watch and recompile for changes
74−watch :: Configuration -> Verbosity -> Rules a -> IO ()
75−watch conf verbosity rules = watch' conf verbosity rules (return ())
7678
77−watch' :: Configuration -> Verbosity -> Rules a -> IO () -> IO ()
78−#ifdef PREVIEW_SERVER
79−watch' conf verbosity rules action = do
79+watch :: Configuration -> Verbosity -> Int -> Bool -> Rules a -> IO ()
80+#ifdef WATCH_SERVER
81+watch conf verbosity port runServer rules = do
8082 watchUpdates conf update
81− _ <- forkIO (action)
82− putStrLn "Press <enter> to quit watching."
83+ _ <- forkIO (server')
8384 loop
8485 where
8586 update = do
8687 (_, ruleSet) <- run conf verbosity rules
8788 return $ rulesPattern ruleSet
8889
89− loop = do
90− line <- getLine
91− if line == ""
92− then putStrLn "Quitting..."
93− else loop
90+ server' :: IO ()
91+ server' = if runServer
92+ then (server conf port)
93+ else (return ())
94+
95+ loop = threadDelay 100000 >> loop
9496#else
95−watch' _ _ _ _ = watchServerDisabled
97+watch _ _ _ _ _ = watchServerDisabled
9698#endif
9799
98−
99100--------------------------------------------------------------------------------
100101-- | Rebuild the site
101102rebuild :: Configuration -> Verbosity -> Rules a -> IO ExitCode
@@ -134,7 +135,9 @@ previewServerDisabled =
134135 , "enable it, set the flag to True and recompile Hakyll."
135136 , "Alternatively, use an external tool to serve your site directory."
136137 ]
138+#endif
137139
140+#ifndef WATCH_SERVER
138141watchServerDisabled :: IO ()
139142watchServerDisabled =
140143 mapM_ putStrLn
@@ -144,5 +147,5 @@ watchServerDisabled =
144147 , "enable it, set the flag to True and recompile Hakyll."
145148 , "Alternatively, use an external tool to serve your site directory."
146149 ]
147−
148150#endif
151+
src/Hakyll/Main.hs+18−12
@@ -41,15 +41,15 @@ hakyllWith conf rules = do
4141 if internal_links args' then Check.InternalLinks else Check.All
4242
4343 case args' of
44− Build _ -> Commands.build conf verbosity' rules >>= exitWith
45− Check _ _ -> Commands.check conf verbosity' check'
46− Clean _ -> Commands.clean conf
47− Deploy _ -> Commands.deploy conf >>= exitWith
48− Help _ -> showHelp
49− Preview _ p -> Commands.preview conf verbosity' rules p
50− Rebuild _ -> Commands.rebuild conf verbosity' rules >>= exitWith
51− Server _ _ -> Commands.server conf (port args')
52− Watch _ -> Commands.watch conf verbosity' rules
44+ Build _ -> Commands.build conf verbosity' rules >>= exitWith
45+ Check _ _ -> Commands.check conf verbosity' check'
46+ Clean _ -> Commands.clean conf
47+ Deploy _ -> Commands.deploy conf >>= exitWith
48+ Help _ -> showHelp
49+ Preview _ p -> Commands.preview conf verbosity' rules p
50+ Rebuild _ -> Commands.rebuild conf verbosity' rules >>= exitWith
51+ Server _ _ -> Commands.server conf (port args')
52+ Watch _ p s -> Commands.watch conf verbosity' p (not s) rules
5353
5454
5555--------------------------------------------------------------------------------
@@ -68,7 +68,7 @@ data HakyllArgs
6868 | Preview {verbose :: Bool, port :: Int}
6969 | Rebuild {verbose :: Bool}
7070 | Server {verbose :: Bool, port :: Int}
71− | Watch {verbose :: Bool}
71+ | Watch {verbose :: Bool, port :: Int, no_server :: Bool }
7272 deriving (Data, Typeable, Show)
7373
7474
@@ -82,11 +82,12 @@ hakyllArgs = modes
8282 , (Deploy $ verboseFlag def) &= help "Upload/deploy your site"
8383 , (Help $ verboseFlag def) &= help "Show this message" &= auto
8484 , (Preview (verboseFlag def) (portFlag 8000)) &=
85− help "Start a preview server and autocompile on changes"
85+ help "[Deprecated] Please use the watch command"
8686 , (Rebuild $ verboseFlag def) &= help "Clean and build again"
8787 , (Server (verboseFlag def) (portFlag 8000)) &=
8888 help "Start a preview server"
89− , (Watch (verboseFlag def) &= help "Autocompile on changes")
89+ , (Watch (verboseFlag def) (portFlag 8000) (noServerFlag False) &=
90+ help "Autocompile on changes and start a preview server")
9091 ] &= help "Hakyll static site compiler" &= program progName
9192
9293
@@ -96,6 +97,11 @@ verboseFlag x = x &= help "Run in verbose mode"
9697{-# INLINE verboseFlag #-}
9798
9899
100+--------------------------------------------------------------------------------
101+noServerFlag :: Data a => a -> a
102+noServerFlag x = x &= help "Disable the built-in web server"
103+{-# INLINE noServerFlag #-}
104+
99105--------------------------------------------------------------------------------
100106portFlag :: Data a => a -> a
101107portFlag x = x &= help "Port to listen on"