diff options
Diffstat (limited to '')
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | client/src/Messages.elm | 24 | ||||
-rw-r--r-- | server/cafp.cabal | 41 | ||||
-rw-r--r-- | server/src/GenerateElmTypes.hs | 13 | ||||
-rw-r--r-- | server/src/GenerateTypes.hs | 4 |
5 files changed, 66 insertions, 22 deletions
@@ -1,3 +1,9 @@ +HS_SOURCES=$(shell find server/lib/ server/src -name '*.hs') +ELM_MESSAGES_MODULE=client/src/Messages.elm + .PHONY: build build: cd server && stack build + +$(ELM_MESSAGES_MODULE): $(HS_SOURCES) + (cd server && stack exec cafp-generate-elm-types) >$(ELM_MESSAGES_MODULE) diff --git a/client/src/Messages.elm b/client/src/Messages.elm new file mode 100644 index 0000000..da10d22 --- /dev/null +++ b/client/src/Messages.elm @@ -0,0 +1,24 @@ +module Messages exposing(..) + +import Json.Decode +import Json.Encode exposing (Value) +-- The following module comes from bartavelle/json-helpers +import Json.Helpers exposing (..) +import Dict exposing (Dict) +import Set exposing (Set) + + +type ServerMessage = + Welcome + +jsonDecServerMessage : Json.Decode.Decoder ( ServerMessage ) +jsonDecServerMessage = + let jsonDecDictServerMessage = Dict.fromList [("Welcome", Welcome)] + in decodeSumUnaries "ServerMessage" jsonDecDictServerMessage + +jsonEncServerMessage : ServerMessage -> Value +jsonEncServerMessage val = + case val of + Welcome -> Json.Encode.string "Welcome" + + diff --git a/server/cafp.cabal b/server/cafp.cabal index 08b479c..fc52b4f 100644 --- a/server/cafp.cabal +++ b/server/cafp.cabal @@ -1,14 +1,14 @@ -Name: cafp -Version: 0.1.0 -Synopsis: Cards Against Functional Programming -License: BSD3 -License-file: LICENSE -Author: Jasper Van der Jeugt <m@jaspervdj.be> -Maintainer: Jasper Van der Jeugt <m@jaspervdj.be> -Copyright: 2020 Jasper Van der Jeugt <m@jaspervdj.be> -Category: Language -Build-type: Simple -Cabal-version: 1.18 +Name: cafp +Version: 0.1.0 +Synopsis: Cards Against Functional Programming +License: BSD3 +License-file: LICENSE +Author: Jasper Van der Jeugt <m@jaspervdj.be> +Maintainer: Jasper Van der Jeugt <m@jaspervdj.be> +Copyright: 2020 Jasper Van der Jeugt <m@jaspervdj.be> +Category: Language +Build-type: Simple +Cabal-version: 1.18 Library Default-language: Haskell2010 @@ -19,11 +19,16 @@ Library Cafp.Messages Build-depends: - base >= 4.9 && < 5 + base >= 4.9 && < 5, + elm-bridge >= 0.5 && < 0.6 -Executable cafp-generate-types - Hs-source-dirs: src - Main-is: GenerateTypes.hs - Default-language: Haskell2010 - Ghc-options: -Wall - build-depends: base, cafp +Executable cafp-generate-elm-types + Hs-source-dirs: src + Main-is: GenerateElmTypes.hs + Default-language: Haskell2010 + Ghc-options: -Wall + + Build-depends: + base >= 4.9 && < 5, + cafp, + elm-bridge >= 0.5 && < 0.6 diff --git a/server/src/GenerateElmTypes.hs b/server/src/GenerateElmTypes.hs new file mode 100644 index 0000000..e8aa25b --- /dev/null +++ b/server/src/GenerateElmTypes.hs @@ -0,0 +1,13 @@ +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-# LANGUAGE TemplateHaskell #-} +import Cafp.Messages +import Elm.Derive +import Elm.Module +import Data.Proxy + +deriveBoth defaultOptions ''ServerMessage + +main :: IO () +main = putStrLn $ makeElmModule "Messages" + [ DefineElm (Proxy :: Proxy ServerMessage) + ] diff --git a/server/src/GenerateTypes.hs b/server/src/GenerateTypes.hs deleted file mode 100644 index 730d9fb..0000000 --- a/server/src/GenerateTypes.hs +++ /dev/null @@ -1,4 +0,0 @@ -import Cafp.Messages - -main :: IO () -main = print Welcome |