From 125a792ec885d16fc0e41751d073caf2da9f2301 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Tue, 28 Jul 2020 23:25:57 +0200 Subject: Mess around --- Makefile | 6 ++++++ client/src/Messages.elm | 24 ++++++++++++++++++++++++ server/cafp.cabal | 41 +++++++++++++++++++++++------------------ server/src/GenerateElmTypes.hs | 13 +++++++++++++ server/src/GenerateTypes.hs | 4 ---- 5 files changed, 66 insertions(+), 22 deletions(-) create mode 100644 client/src/Messages.elm create mode 100644 server/src/GenerateElmTypes.hs delete mode 100644 server/src/GenerateTypes.hs diff --git a/Makefile b/Makefile index 90142d8..9260540 100644 --- a/Makefile +++ b/Makefile @@ -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 -Maintainer: Jasper Van der Jeugt -Copyright: 2020 Jasper Van der Jeugt -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 +Maintainer: Jasper Van der Jeugt +Copyright: 2020 Jasper Van der Jeugt +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 -- cgit v1.2.3