agrafix / elm-bridge

Haskell: Derive Elm types from Haskell types
BSD 3-Clause "New" or "Revised" License
100 stars 27 forks source link

Making EndToEnd test run with elm-test. #36

Closed tmbull closed 6 years ago

tmbull commented 6 years ago

If you wrote the module in this way for a reason, feel free to close the PR. But I made these changes below so that I could run the output with elm-test. BTW, the output compiles and all of the tests pass with the 0.19 version of elm-test!

bartavelle commented 6 years ago

Oh I did not realize it was ported!

janwirth commented 6 years ago

Hey guys - Great work on this :) Really looking forward. Just curous how I can track the progress or how I could even use this just now!

I want to build this here: https://github.com/FranzSkuffka/functure/blob/master/README.md and I am curious if you guys want to to tune in :)

bartavelle commented 6 years ago

@FranzSkuffka this particular PR is merged, so what is missing for you?

janwirth commented 6 years ago

I do not know how to install and run thus in a stack project.

bartavelle commented 6 years ago

Oh, you have to add elm-bridge as a dependency to your library (probably in package.yaml, and then as an extra dependency in stack.yaml if it complains). Then you have to replace all calls to deriveJson to deriveBoth. Finally, you have to add an extra executable that will output the Elm code, as in the project README.

janwirth commented 6 years ago

Thanks :)

janwirth commented 6 years ago

Update: I am using this with elm 0.19. Okey so I added this repo to my extra-deps and I get the following output:

module Foo 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 alias Foo  =
   { f_name: String
   , f_blablub: Int
   }

jsonDecFoo : Json.Decode.Decoder ( Foo )
jsonDecFoo =
   Json.Decode.succeed (\pf_name pf_blablub -> {f_name = pf_name, f_blablub = pf_blablub})
   |> required "f_name" (Json.Decode.string)
   |> required "f_blablub" (Json.Decode.int)

jsonEncFoo : Foo -> Value
jsonEncFoo  val =
   Json.Encode.object
   [ ("f_name", Json.Encode.string val.f_name)
   , ("f_blablub", Json.Encode.int val.f_blablub)
   ]

I am now using sed to replace the deps

stack exec impuls-api-bridge | sed 's|Helpers|Decode.Pipeline|' | sed 's|bartavelle/json-helpers|NoRedInk/elm-json-decode-pipeline|'

And I get a compiling elm module :tada:

Am I doing anything wrong? I assumed the module to be 0.19-ready - Am I misusing stack?

bartavelle commented 6 years ago

Yeah, the 0.19 compatible version is not out yet, I have a couple things to do, but got no time these days :/

janwirth commented 6 years ago

No worries - thank you very much for your work. If you could sketch out a roadmap or sth I would love to see if I can help.