2
2
{-# LANGUAGE TemplateHaskell #-}
3
3
{-# LANGUAGE TypeOperators #-}
4
4
5
- module Lib
6
- ( runServer ,
7
- runCodegen ,
8
- app ,
5
+ module Server
6
+ ( Server. run ,
7
+ APIRoutes ,
9
8
)
10
9
where
11
10
@@ -16,20 +15,20 @@ import Network.Wai
16
15
import Network.Wai.Handler.Warp
17
16
import Network.Wai.Logger (withStdoutLogger )
18
17
import Servant
19
- import Servant.Elm (DefineElm (DefineElm ), Proxy (Proxy ), defElmImports , defElmOptions , generateElmModuleWith )
20
18
import System.Environment (lookupEnv )
21
- import qualified System.Process
22
- import System.Process (cwd , proc )
23
19
24
20
type APIRoutes = " game" :> Get '[JSON ] Game. State
25
21
22
+ deriveBoth defaultOptions {constructorTagModifier = Game. tagToApiLabel} ''Game. Country
23
+ deriveBoth defaultOptions ''Game. State
24
+
26
25
type Routes =
27
26
APIRoutes
28
27
:<|> " _build" :> Raw
29
28
:<|> Raw
30
29
31
- runServer :: IO ()
32
- runServer = do
30
+ run :: IO ()
31
+ run = do
33
32
maybePort <- lookupEnv " PORT"
34
33
let port = fromMaybe 8080 (fmap read maybePort)
35
34
withStdoutLogger $ \ logger -> do
@@ -51,25 +50,3 @@ server =
51
50
return Game. new
52
51
:<|> serveDirectoryWebApp " ui/_build"
53
52
:<|> serveDirectoryFileServer " ui/static"
54
-
55
- deriveBoth defaultOptions {constructorTagModifier = Game. tagToApiLabel} ''Game. Country
56
- deriveBoth defaultOptions ''Game. State
57
-
58
- runCodegen :: IO ()
59
- runCodegen =
60
- let outputDir = " ./ui/generated"
61
- in do
62
- putStrLn " Deleting old generated code..."
63
- putStrLn " Generating Elm code from API..."
64
- generateElmModuleWith
65
- defElmOptions
66
- [" Api" ]
67
- defElmImports
68
- outputDir
69
- [ DefineElm (Proxy :: Proxy Game. State ),
70
- DefineElm (Proxy :: Proxy Game. Country )
71
- ]
72
- (Proxy :: Proxy APIRoutes )
73
- putStrLn " Formatting generated code using elm-format..."
74
- System.Process. createProcess (proc " elm-format" [" Api.elm" , " --yes" ]) {cwd = Just outputDir}
75
- putStrLn " Done!"
0 commit comments