packages feed

wai-handler-devel 0.1.1.1 → 0.1.1.2

raw patch · 3 files changed

+80/−32 lines, 3 filesdep ~directorynew-component:exe:wai-handler-devel-unwatched

Dependency ranges changed: directory

Files

Network/Wai/Handler/DevelServer.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-}-module Network.Wai.Handler.DevelServer (run) where+module Network.Wai.Handler.DevelServer (run, runNoWatch) where  import Language.Haskell.Interpreter import Network.Wai@@ -32,6 +32,14 @@  type FunctionName = String +runNoWatch :: Port -> ModuleName -> FunctionName -> [FilePath] -> IO ()+runNoWatch port modu func dirs = do+    queue <- C.newChan+    mqueue <- M.newMVar queue+    startApp queue $ loadingApp Nothing+    reload modu func mqueue dirs Nothing+    run' port mqueue+ run :: Port -> ModuleName -> FunctionName -> [FilePath] -> IO () run port modu func dirs = do     queue <- C.newChan@@ -58,13 +66,14 @@             $ "Exception thrown while running application\n\n" ++ show e     void x = x >> return () +getTimes = E.handle (constSE $ return []) . mapM getModificationTime+constSE :: x -> SomeException -> x+constSE = const+ fillApp :: String -> String -> M.MVar Queue -> [FilePath] -> IO () fillApp modu func mqueue dirs =     go Nothing []   where-    constSE :: x -> SomeException -> x-    constSE = const-    getTimes = E.handle (constSE $ return []) . mapM getModificationTime     go prevError prevFiles = do         toReload <-             if null prevFiles@@ -74,35 +83,38 @@                     return $ times /= map snd prevFiles         (newError, newFiles) <-             if toReload-                then reload prevError+                then reload modu func mqueue dirs prevError                 else return (prevError, prevFiles)         threadDelay 1000000         go newError newFiles-    reload prevError = do-        case prevError of-             Nothing -> putStrLn "Attempting to interpret your app..."-             _       -> return ()-        loadingApp' prevError mqueue-        res <- theapp modu func-        case res of-            Left err -> do-                if show (Just err) /= show prevError-                   then putStrLn $ "Compile failed: " ++ showInterpError err-                   else return ()-                loadingApp' (Just $ toException err) mqueue-                return (Just $ toException err, [])-            Right (app, files') -> E.handle onInitErr $ do-                files'' <- mapM fileList dirs-                let files = concat $ files' : files''-                putStrLn "Interpreting success, new app loaded"-                E.handle onInitErr $ do-                    swapApp app mqueue-                    times <- getTimes files-                    return (Nothing, zip files times)-    onInitErr e = do-        putStrLn $ "Error initializing application: " ++ show e-        loadingApp' (Just e) mqueue-        return (Just e, [])++-- reload :: String -> String -> M.MVar Queue -> [FilePath] -> Maybe SomeException -> IO (Maybe SomeException, [ClockTime])+reload modu func mqueue dirs prevError = do+    case prevError of+         Nothing -> putStrLn "Attempting to interpret your app..."+         _       -> return ()+    loadingApp' prevError mqueue+    res <- theapp modu func+    case res of+        Left err -> do+            if show (Just err) /= show prevError+               then putStrLn $ "Compile failed: " ++ showInterpError err+               else return ()+            loadingApp' (Just $ toException err) mqueue+            return (Just $ toException err, [])+        Right (app, files') -> E.handle onInitErr $ do+            files'' <- mapM fileList dirs+            let files = concat $ files' : files''+            putStrLn "Interpreting success, new app loaded"+            E.handle onInitErr $ do+                swapApp app mqueue+                times <- getTimes files+                return (Nothing, zip files times)+    where+        onInitErr e = do+            putStrLn $ "Error initializing application: " ++ show e+            loadingApp' (Just e) mqueue+            return (Just e, [])  showInterpError :: InterpreterError -> String showInterpError (WontCompile errs) =
+ wai-handler-devel-unwatched.hs view
@@ -0,0 +1,31 @@+{-# LANGUAGE DeriveDataTypeable #-}+import Network.Wai.Handler.DevelServer (runNoWatch)+import System.Console.CmdArgs+import Control.Concurrent (forkIO)++data Devel = Devel+    { port :: Int+    , moduleName :: String+    , function :: String+    , yesod :: Bool+    }+    deriving (Show, Data, Typeable)++main :: IO ()+main = do+    Devel p m f y <- cmdArgs Devel+        { port = 3000 &= argPos 0 &= typ "PORT"+        , moduleName = "" &= argPos 1 &= typ "MODULE"+        , function = "" &= argPos 2 &= typ "FUNCTION"+        , yesod = False &= help "Monitor typical Yesod folders (hamlet, etc)"+        } &= summary "WAI development web server"+    _ <- forkIO $ runNoWatch p m f $ folders y+    go+  where+    folders False = []+    folders True = ["hamlet", "cassius", "julius"]+    go = do+        x <- getLine+        case x of+            'q':_ -> putStrLn "Quitting, goodbye!"+            _ -> go
wai-handler-devel.cabal view
@@ -1,5 +1,5 @@ Name:                wai-handler-devel-Version:             0.1.1.1+Version:             0.1.1.2 Synopsis:            WAI server that automatically reloads code after modification. Description:         This handler automatically reloads your source code upon any changes. It works by using the hint package, essentially embedding GHC inside the handler. The handler (both the executable and library) takes three arguments: the port to listen on, the module name containing the application function, and the name of the function.                      .@@ -24,7 +24,7 @@   Build-Depends:     base >= 3 && < 5                    , wai >= 0.2.1 && < 0.3                    , wai-extra >= 0.2.3 && < 0.3-                   , directory >= 1.0 && < 1.1+                   , directory >= 1.0 && < 1.2                    , network >= 2.2 && < 2.4                    , bytestring >= 0.9 && < 0.10                    , hint >= 0.3.2.3 && < 0.4@@ -36,3 +36,8 @@   Build-Depends:     cmdargs >= 0.4 && < 0.7   ghc-options:       -Wall -O2 -threaded   main-is:           wai-handler-devel.hs++Executable           wai-handler-devel-unwatched+  Build-Depends:     cmdargs >= 0.4 && < 0.7+  ghc-options:       -Wall -O2 -threaded+  main-is:           wai-handler-devel-unwatched.hs