on master help sign in
ob run: Simplify ghcid args
commit0f16376583cf2a5ae56264cf6b3239ddf88675f0 authorLuigy Leon <luigy@outlook.com> dateTue 15 May 2018, 21:02 (8 years ago) parentf9f6d36
2 files changed+17−12
lib/command/src/Obelisk/Command/Run.hs+3−11 lib/run/src/Obelisk/Run.hs+14−1
lib/command/src/Obelisk/Command/Run.hs+3−11
@@ -43,19 +43,11 @@ run = do
4343 when (not (null pkgDirErrs)) $
4444 putLog Warning $ T.pack $ "Failed to find pkgs in " <> intercalate ", " pkgDirErrs
4545 let dotGhci = unlines
46− [ ":set args --quiet --port " <> show freePort
47− , ":set -i" <> intercalate ":" (mconcat hsSrcDirs)
48− , ":set -XScopedTypeVariables"
46+ [ ":set -i" <> intercalate ":" (mconcat hsSrcDirs)
4947 , ":add Backend Frontend"
50− , ":module + System.IO Control.Exception Control.Concurrent Obelisk.Run Frontend Backend"
51− ]
52− testCmd = unlines
53− [ "let handleBackendErr (_ :: SomeException) = hPutStrLn stderr \"backend stopped; make a change to your code to reload\""
54− , "backendTid <- forkIO $ handle handleBackendErr backend"
55− , "let conf = defRunConfig { _runConfig_redirectPort = " <> show freePort <> "}"
56− , "runWidget conf frontend"
57− , "killThread backendTid"
48+ , ":module + Obelisk.Run Frontend Backend"
5849 ]
50+ testCmd = unwords ["Obelisk.Run.run", show freePort , "backend", "frontend"]
5951 withSystemTempDirectory "ob-ghci" $ \fp -> do
6052 let dotGhciPath = fp </> ".ghci"
6153 liftIO $ do
lib/run/src/Obelisk/Run.hs+14−1
@@ -21,8 +21,21 @@ import Network.Wai (Application)
2121import Network.Wai.Handler.Warp
2222import Network.WebSockets.Connection (defaultConnectionOptions)
2323import Network.Wai.Handler.Warp.Internal (settingsPort, settingsHost)
24−import System.Process
2524import Reflex.Dom.Core
25+import System.Environment
26+import System.IO
27+import System.Process
28+
29+run :: Int -- ^ Port to run the backend
30+ -> IO () -- ^ Backend
31+ -> Widget () () -- ^ Frontend widget
32+ -> IO ()
33+run port backend frontend = do
34+ let handleBackendErr (_ :: SomeException) = hPutStrLn stderr "backend stopped; make a change to your code to reload"
35+ backendTid <- forkIO $ handle handleBackendErr $ withArgs ["--quiet", "--port", show port] backend
36+ let conf = defRunConfig { _runConfig_redirectPort = port }
37+ runWidget conf frontend
38+ killThread backendTid
2639
2740runWidget :: RunConfig -> Widget () () -> IO ()
2841runWidget conf w = do