on master help sign in
Merge remote-tracking branch 'origin/routes' into reunification
commitf5b80c5fba3762d25522d4c11c4cb388944a15d8 authorhsloan <ishaqsloan@gmail.com> dateWed 12 Sep 2018, 15:49 (8 years ago) parentfd8bcdad9589d7
11 files changed+76−48
lib/command/src/Obelisk/Command.hs+3 lib/command/src/Obelisk/Command/Run.hs+10−2 skeleton/backend/backend.cabal+1−5 skeleton/backend/src-bin/main.hs+3−17 skeleton/backend/src/Backend.hs+12−6 skeleton/common/common.cabal+4 skeleton/common/src/Common/Route.hs+24 skeleton/devel/Devel.hs−10 skeleton/frontend/frontend.cabal+4−1 skeleton/frontend/src-bin/main.hs+7−2 skeleton/frontend/src/Frontend.hs+8−5
lib/command/src/Obelisk/Command.hs+3
@@ -92,6 +92,7 @@ data ObCommand
9292 | ObCommand_Run
9393 | ObCommand_Thunk ThunkCommand
9494 | ObCommand_Repl
95+ | ObCommand_Watch
9596 | ObCommand_Upgrade (Maybe Text)
9697 | ObCommand_Internal ObInternal
9798 deriving Show
@@ -131,6 +132,7 @@ obCommand cfg = hsubparser
131132 , command "run" $ info (pure ObCommand_Run) $ progDesc "Run current project in development mode"
132133 , command "thunk" $ info (ObCommand_Thunk <$> thunkCommand) $ progDesc "Manipulate thunk directories"
133134 , command "repl" $ info (pure ObCommand_Repl) $ progDesc "Open an interactive interpreter"
135+ , command "watch" $ info (pure ObCommand_Watch) $ progDesc "Watch current project for errors and warnings"
134136 , command "upgrade" $ info (ObCommand_Upgrade <$> argument (maybeReader $ Just . Just . T.pack) (action "branch" <> metavar "GITBRANCH" <> value Nothing <> help "Git branch of obelisk to update to (defaults to the thunk's branch)")) $ progDesc "Upgrade Obelisk in the project"
135137 ])
136138 <|> subparser
@@ -399,6 +401,7 @@ ob = \case
399401 ThunkCommand_Unpack thunks -> mapM_ unpackThunk thunks
400402 ThunkCommand_Pack thunks -> forM_ thunks $ \(ThunkPackOpts dir upstream) -> packThunk dir (T.pack upstream)
401403 ObCommand_Repl -> runRepl
404+ ObCommand_Watch -> inNixShell' $ static runWatch
402405 ObCommand_Upgrade branch -> do
403406 upgradeObelisk "." branch
404407 ObCommand_Internal icmd -> case icmd of
lib/command/src/Obelisk/Command/Run.hs+10−2
@@ -38,7 +38,7 @@ run = do
3838 pkgs <- getLocalPkgs
3939 withGhciScript pkgs $ \dotGhciPath -> do
4040 freePort <- getFreePort
41− runGhcid dotGhciPath $ Just $ unwords ["main", show freePort]
41+ runGhcid dotGhciPath $ Just $ unwords ["run", show freePort, "Backend.backend", "Frontend.frontend"]
4242
4343runRepl :: MonadObelisk m => m ()
4444runRepl = do
@@ -46,6 +46,11 @@ runRepl = do
4646 withGhciScript pkgs $ \dotGhciPath -> do
4747 runGhciRepl dotGhciPath
4848
49+runWatch :: MonadObelisk m => m ()
50+runWatch = do
51+ pkgs <- getLocalPkgs
52+ withGhciScript pkgs $ \dotGhciPath -> runGhcid dotGhciPath Nothing
53+
4954-- | Relative paths to local packages of an obelisk project
5055-- TODO a way to query this
5156getLocalPkgs :: Applicative f => f [FilePath]
@@ -98,7 +103,10 @@ withGhciScript pkgs f = do
98103
99104 let dotGhci = unlines
100105 [ ":set -i" <> intercalate ":" (mconcat hsSrcDirs)
101− , ":load ./devel/Devel.hs" -- TODO more robust filepath
106+ , ":load Backend Frontend"
107+ , "import Obelisk.Run"
108+ , "import qualified Frontend"
109+ , "import qualified Backend"
102110 ]
103111 withSystemTempDirectory "ob-ghci" $ \fp -> do
104112 let dotGhciPath = fp </> ".ghci"
skeleton/backend/backend.cabal+1−5
@@ -11,6 +11,7 @@ library
1111 , common
1212 , frontend
1313 , obelisk-backend
14+ , obelisk-route
1415 exposed-modules:
1516 Backend
1617 ghc-options: -Wall
@@ -24,9 +25,4 @@ executable backend
2425 , backend
2526 , common
2627 , frontend
27− , lens
28− , modern-uri
2928 , obelisk-backend
30− , obelisk-executable-config
31− , obelisk-executable-config-inject
32− , text
skeleton/backend/src-bin/main.hs+3−17
@@ -1,20 +1,6 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−import Control.Exception
3−import Control.Lens
4−import Data.Maybe
5−import Data.Text.Encoding
6−import Obelisk.ExecutableConfig (get)
7−import System.Environment
8−import qualified Text.URI as URI
9−import Text.URI.Lens
10−
111import Backend
2+import Frontend
3+import Obelisk.Backend
124
135main :: IO ()
14−main = do
15− Just route <- get "common/route"
16− port <- case URI.mkURI route of
17− Left err -> fail $ show err
18− Right uri -> return $ fromMaybe 8000 $ uri ^? uriAuthority . _Right . authPort . _Just
19− withArgs ["--port", show port] backend
20−
6+main = runBackend backend frontend
skeleton/backend/src/Backend.hs+12−6
@@ -1,10 +1,16 @@
1+{-# LANGUAGE EmptyCase #-}
2+{-# LANGUAGE FlexibleContexts #-}
3+{-# LANGUAGE LambdaCase #-}
4+{-# LANGUAGE RankNTypes #-}
5+{-# LANGUAGE TypeFamilies #-}
16module Backend where
27
3−import Common.Api
4−import Frontend
5−import qualified Obelisk.Backend as Ob
8+import Common.Route
9+import Obelisk.Backend
10+import Obelisk.Route
611
7−backend :: IO ()
8−backend = Ob.backend Ob.def
9− { Ob._backendConfig_head = fst frontend
12+backend :: Backend Void1 IndexOnlyRoute
13+backend = Backend
14+ { _backend_run = \serve -> serve $ const $ return ()
15+ , _backend_routeEncoder = backendRouteEncoder
1016 }
skeleton/common/common.cabal+4
@@ -6,6 +6,10 @@ build-type: Simple
66library
77 hs-source-dirs: src
88 build-depends: base
9+ , obelisk-route
10+ , mtl
11+ , text
912
1013 exposed-modules:
1114 Common.Api
15+ Common.Route
skeleton/common/src/Common/Route.hsnew file+24
@@ -0,0 +1,24 @@
1+{-# LANGUAGE EmptyCase #-}
2+{-# LANGUAGE FlexibleContexts #-}
3+{-# LANGUAGE GADTs #-}
4+{-# LANGUAGE LambdaCase #-}
5+{-# LANGUAGE RankNTypes #-}
6+module Common.Route where
7+
8+import Prelude hiding ((.))
9+
10+import Control.Category
11+import Control.Monad.Except
12+import Data.Text
13+import Data.Functor.Sum
14+import Obelisk.Route
15+
16+backendRouteEncoder
17+ :: forall check parse. (check ~ parse, MonadError Text parse)
18+ => Encoder check parse (R (Sum Void1 (ObeliskRoute IndexOnlyRoute))) PageName
19+backendRouteEncoder = Encoder $ do
20+ let componentEncoder = shadowEncoder void1Encoder $ obeliskRouteComponentEncoder indexOnlyRouteComponentEncoder
21+ restEncoder <- checkObeliskRouteRestEncoder indexOnlyRouteRestEncoder
22+ checkEncoder $ pathComponentEncoder (componentEncoder . someSumEncoder) $ \case
23+ InL backendRoute -> case backendRoute of {}
24+ InR obeliskRoute -> runValidEncoderFunc restEncoder obeliskRoute
skeleton/devel/Devel.hsdeleted−10
@@ -1,10 +0,0 @@
1−module Devel where
2−
3−import Obelisk.Run
4−
5−import Backend
6−import Frontend
7−
8−main :: Int -> IO ()
9−main port = run port backend frontend
10−
skeleton/frontend/frontend.cabal+4−1
@@ -7,6 +7,8 @@ library
77 hs-source-dirs: src
88 build-depends: base
99 , common
10+ , obelisk-frontend
11+ , obelisk-route
1012 , reflex-dom
1113 , static
1214 , text
@@ -19,9 +21,10 @@ executable frontend
1921 hs-source-dirs: src-bin
2022 build-depends: base
2123 , common
24+ , obelisk-frontend
25+ , obelisk-route
2226 , reflex-dom
2327 , static
24− , text
2528 , frontend
2629 --TODO: Make these ghc-options optional
2730 ghc-options: -threaded
skeleton/frontend/src-bin/main.hs+7−2
@@ -1,5 +1,10 @@
1−import Reflex.Dom
21import Frontend
2+import Common.Route
3+import Obelisk.Frontend
4+import Obelisk.Route.Frontend
5+import Reflex.Dom
36
47main :: IO ()
5−main = mainWidget $ snd frontend
8+main = do
9+ let Right validFullEncoder = checkEncoder backendRouteEncoder
10+ run $ runFrontend validFullEncoder frontend
skeleton/frontend/src/Frontend.hs+8−5
@@ -4,16 +4,19 @@
44module Frontend where
55
66import qualified Data.Text as T
7+import Obelisk.Frontend
8+import Obelisk.Route
79import Reflex.Dom.Core
810
911import Common.Api
1012import Static
1113
12−frontend :: (StaticWidget x (), Widget x ())
13−frontend = (head', body)
14− where
15− head' = el "title" $ text "Obelisk Minimal Example"
16− body = do
14+frontend :: Frontend (R IndexOnlyRoute)
15+frontend = Frontend
16+ { _frontend_head = el "title" $ text "Obelisk Minimal Example"
17+ , _frontend_body = do
1718 text "Welcome to Obelisk!"
1819 el "p" $ text $ T.pack commonStuff
1920 elAttr "img" ("src" =: static @"obelisk.jpg") blank
21+ , _frontend_notFoundRoute = const $ IndexOnlyRoute :/ ()
22+ }