Code Monkey home page Code Monkey logo

elm-codegen's Introduction

Elm CodeGen

Elm CodeGen is an Elm package and CLI tool for generating Elm code.

The goal is to be easier to write and more maintainable than that string template you have lying around. 😏

Here's what this tool does for you in order to make generating code simpler.

  1. Automatic imports β€” Import declarations are calculated.
  2. Built in type inference β€” The types for your generated code are inferred, which means generated things can figure out their own type signatures.
  3. Use existing packages easily β€” For generating code that uses a specific library such as elm-ui, the elm-codegen CLI can create some Elm code to help you out. Check out the Using packages guide to get a better idea of what this looks like!

To get started, here's a small example to give you an idea of what the code looks like!

Elm.declaration "anExample"
    (Elm.record
        [ ("name", Elm.string "a fancy string!")
        , ("fancy", Elm.bool True)
        ]
    )
    |> Elm.ToString.declaration

The above will generate the following string:

anExample : { name : String, fancy : Bool }
anExample =
    { name = "a fancy string!"
    , fancy = True
    }

Check out the guide!

And finally, the elm-codegen package documentation.

Using the CLI

npm install -g elm-codegen

Then you can start a codegen project using:

elm-codegen init

elm-codegen's People

Contributors

aaronwhite avatar absynce avatar dillonkearns avatar jfmengels avatar kirchner avatar lydell avatar marc136 avatar mdevlamynck avatar mdgriffith avatar minibill avatar nqthqn avatar r-k-b avatar tesk9 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

elm-codegen's Issues

Type inference difference between Elm.ToString.* and Elm.file

Using generated package code for rtfeldman/elm-css works when using Elm.ToString helpers, but not when using Elm.file.

When using Elm.file, Gen.Css.marginRight (Gen.Css.px 1) will cause an error like ELM-CODEGEN ERROR -- I found Css.LengthOrAuto compatible_0 But I was expecting: Css.Px

I believe this is because elm-css does some type-trickery in order to allow helpers that take "different" units, like pct, px, etc. A Css.Px is a ExplicitLength, which is a Css.LengthOrAuto.

Ellie example illustrating the problem when using Elm.file


Should users only use file if they're working with generated code that results from Generate.elm, rather than using Gen.* directly?

Support for inline comments

I'd like to be able to conveniently generate inline comments.

The main use I have for generated Elm code is copy-pastable example code for reusable components. Sometimes these components need to be hooked up to application Msgs in order to do anything. I want to be able to provide example code, but I don't want to write out a bunch of extra TEA wiring, so I will often comment out a non-functional sample implementation.

For example, the generated Elm code that I currently use for a Tabs component example includes commented out code around adding tooltips:

     Tabs.build { id = 0, idString = "tab-1" }
	    [ Tabs.tabString "Tab 1"
	    , Tabs.panelHtml (text "Panel 1")
	    , Tabs.withTooltip
	       [ Tooltip.plaintext "Tab 1"
	        -- You will need to have a tooltip handler
	        -- , Tooltip.onToggle ToggleTooltip 
	       , Tooltip.open False
	       ]
	    ]

Modules refrenced in tuple deconstructions in let statements are not imported

With the following code

Elm.file [ "Test" ]
Elm.file [ "Test" ]
[ Elm.Let.letIn ( \( _, value ) -> value )
  |> Elm.Let.tuple "_" "value"
      ( Elm.tuple
        Elm.unit
        ( [ Elm.int 1, Elm.int 2, Elm.int 3 ]
          |> Gen.Array.fromList
          |> Gen.Array.get 1
        )
      )
  |> Elm.Let.toExpression
  |> Elm.declaration "test"
]

The following file is generated

module Test exposing (..)


test : Maybe a
test =
    let
        ( _, value ) =
            ( (), Array.get 1 (Array.fromList [ 1, 2, 3 ]) )
    in
    value

Which is missing an import statement for the Array module and does not compile

Deconstructing custom types without case..of

Hi Matthew,

thanks for the awesome package.
It's so awesome in fact, that I'm trying to port my Elm Code generator travelm-agency to use this package under the hood instead of elm-syntax-dsl.

To hide the implementation details of the generated I18n type, I wrapped it in a constructor.
Previously, I unpacked this in the arguments of the generated functions

someFunction :: I18n -> String
someFunction (I18n intl language) = ...

which does not seem to be possible with this package unless I'm missing something.
This isn't mission critical, since I can generate a case..of expression matching on my custom type instead.
I just think that unpacking custom types in arguments or let expressions would be nice.
When unpacking multiple types, you get a nested case expression or you need to match on tuples (which are limited to 3 elements).

I'm not sure about the API since just naming arguments with Strings is very convenient.

Maybe just add a function in Elm.Let, since destructuring of tuples and records is already possible?

How to use elm-codegen in a cli tool

Hi there, I'm struggling to see how to use elm-codegen as part of a cli tool. I've already checkout elm-gql, but I can't connect the dots.

I was expecting something like elm-codegen build that turn the entire codegen folder into a single js file.

Because right now the only way I see is to always copy the codegen folder into the target folder and then run elm-codegen normally. But what happens if there are multiple cli tools that all use codegen under the hood, how can I ensure that a different tool does not override my Generate.elm file?

Elm Language Server has an issue with the directory layout from `elm-codegen init`

Elm Language Server will have the following complaint when it runs in a project that elm-codegen init has created

CONFUSING FILE - I am getting confused when I try to compile this file:

    /my-project/codegen/helpers/Helper.elm

I always check if files appear in any of the "source-directories" listed in your
elm.json to see if there might be some cached information about them. That can
help me compile faster! But in this case, it looks like this file may be in
either of these directories:

    /my-project/codegen
    /my-project/codegen/helpers

Because the root source directory is . when it sees /helpers/SomeFile.elm it thinks that the module is named incorrectly- it doesn't quite have the knowledge to realize that this is essentially a template file.

The easy temporary fix would be to just add it as a source-directory in the root elm-json to quiet it. But then this manifests as a new error because now we have nested source directories.

I always check if files appear in any of the "source-directories" listed in your
elm.json to see if there might be some cached information about them. That can
help me compile faster! But in this case, it looks like this file may be in
either of these directories:

    /my-project/codegen
    /my-project/codegen/helpers

Try to make it so no source directory contains another source directory!

my workaround for the time being has been this fork that moves the . src directory to a nested codegen-src instead, and adds helpers to source-directories as well.

This doesn't actually stop anything for working, but creates a bit of a headache when using Elm Language Server. I can make a PR for this if it is of any interest?

Incorrect type inference for Maybe.map2

To try the project out, I tried recreating the Maybe.map2 function. The following is my generator code:

map2 : Declaration
map2 =
    Elm.declaration "map2" <|
        Elm.fn3
            ( "fn", Nothing )
            ( "maybeA", Nothing )
            ( "maybeB", Nothing )
            (\fn maybeA maybeB ->
                Elm.Case.maybe maybeA
                    { nothing = Elm.nothing
                    , just =
                        ( "a"
                        , \a ->
                            Elm.Case.maybe maybeB
                                { nothing = Elm.nothing
                                , just =
                                    ( "b"
                                    , \b -> Elm.just (Elm.apply fn [ a, b ])
                                    )
                                }
                        )
                    }
            )

And this is the result:

map2 : (a -> b -> fn) -> maybeA -> maybeB -> Maybe fn
map2 fn maybeA maybeB =
    case maybeA of
        Nothing ->
            Nothing

        Just a_1_0 ->
            case maybeB of
                Nothing ->
                    Nothing

                Just b_2_1_0 ->
                    Just (fn a_1_0 b_2_1_0)

The problem is that the type signature should have been

map2 : (a -> b -> c) -> Maybe a -> Maybe b -> Maybe c

Qualified types in same module

https://ellie-app.com/jBhFzgXWv64a1
Hi (: I am not sure if this is a bug/outside scope of this package/I am doing something wrong.

Given

myFile : Elm.File
myFile =
    Elm.file [ "MyFirstFile" ]
        [ Elm.declaration "eightyFour"
            (Elm.value
                { annotation = Just (Elm.Annotation.named [ "MyFirstFile" ] "Custom")
                , importFrom = [ "MyFirstFile" ]
                , name = "Custom"
                }
            )
        ]
myFile.contents == """module MyFirstFile exposing (..)

{-| -}

import MyFirstFile

eightyFour : MyFirstFile.Custom
eightyFour = MyFirstFile.Custom
"""

when I would want the type and expression to not be aliased, and MyFirstFile to not be imported. My use case would be building up expressions without needing to know when they are built which module they are going to be used in. At the moment I do this with elm-syntax by passing file metadata down through expression functions and comparing module directories, but it would be so neat if elm-codegen can do this.

Thank you (:

Infinite type inference loop - no manual fix possible

Hi,
first off: thanks for the incredible work on this tool.
I wanted to use it to generate some boilerplate maps for non-comparable types and ran into problems:

--ELM CODEGEN WARNING-----------------------------------------------------------
In the generated file: MapIdDict.elm

    When trying to figure out the type for insert, I ran into an issue
    
    Infinite type inference loop!  Whoops.  This is an issue with elm-codegen.  If you can report this to the elm-codegen repo, that would be appreciated!
    
    I'm not as smart as the Elm compiler :/, but we're good friends.  I especially get confused when there are a lot of type aliases.
    If you need to, try using Elm.withType to tell me what the type should be!


    generated/MapIdDict.elm was generated!
    However, there was a warning.

For simplicity, I simplified my code to not use any of my custom types but Int instead:

module Generate exposing (main)

{-| -}

import Elm
import Elm.Annotation as Type
import Elm.Case
import Gen.CodeGen.Generate as Generate
import Gen.ManualDict


main : Program {} () ()
main =
    Generate.run
        [ genDict
            { dictTypeName = "MapIdDict"
            , keyType = Type.int
            , comparableType = Type.int
            , toComparable = Basics.identity
            }
        ]


type alias DictConfig =
    { dictTypeName : String
    , keyType : Type.Annotation
    , comparableType : Type.Annotation
    , toComparable : Elm.Expression -> Elm.Expression
    }


genDict : DictConfig -> Elm.File
genDict config =
    let
        v =
            Type.var "v"

        dictAnn =
            Gen.ManualDict.annotation_.dict config.comparableType
                config.keyType
                v

        customAnn =
            Type.namedWith [] config.dictTypeName [ v ]

        wrap dict =
            Elm.apply (Elm.val config.dictTypeName) [ dict ]

        unwrap f dict =
            Elm.Case.custom dict
                (Type.named [] config.dictTypeName)
                [ Elm.Case.branch1 config.dictTypeName
                    ( "dict"
                    , Gen.ManualDict.annotation_.dict
                        config.comparableType
                        config.keyType
                        (Type.var "v")
                    )
                    f
                ]

        withWrap f = unwrap f >> wrap         
    in
    Elm.file [ config.dictTypeName ]
        [ Elm.customTypeWith config.dictTypeName
            [ "v" ]
            [ Elm.variantWith config.dictTypeName [ dictAnn ] ]
        , wrap Gen.ManualDict.empty |> Elm.withType customAnn |> Elm.declaration "empty"
        , Elm.fn3 ( "k", Just config.keyType )
            ( "v", Just v )
            ( "dict"
            , Just customAnn
            )
            (\key value -> withWrap (Gen.ManualDict.insert config.toComparable key value))
            |> Elm.withType (Type.function [ config.keyType, v, customAnn ] customAnn)
            |> Elm.declaration "insert"
        ]

The generated file looks like this:

module MapIdDict exposing (..)

import ManualDict


type MapIdDict v
    = MapIdDict (ManualDict.Dict Int Int v)


empty : MapIdDict v
empty =
    MapIdDict ManualDict.empty


insert k v dict =
    MapIdDict
        (case dict of
             MapIdDict dict0 ->
                 ManualDict.insert (\insertUnpack -> insertUnpack) k v dict0
        )

Note the missing annotation on insert. Even though I specified types on all parameters and the function itself,
the issue persists. The code itself is fine, the Elm compiler correctly infers the type.

Expose declarations in `import` statements

Is it possible to expose some declarations in import statements?

Before:

import Html
import Html.Attributes

Html.div
    [ Html.Attributes.class "hello" ]
    [ Html.text "Hello world!" ]

After:

import Html exposing (div, text)
import Html.Attributes exposing (class)

div
    [ class "hello" ]
    [ text "Hello world!" ]

Broken dependencies after elm-codegen init

I did the following (a couple of times, on Linux, on Windows)

$ mkdir foo
$ cd foo
$ elm-codegen init
$ elm-codegen run

Every time I got:

The dependencies in your elm.json are not compatible.

Did you change them by hand? Try to change it back! It is much more reliable to
add dependencies with elm install or the dependency management tool in
elm reactor.

...

The following seems to work though:

$ mkdir foo
$ cd foo
$ elm-codegen init
$ cd codegen
$ rm elm.json
$ elm init
$ elm install mdgriffith/elm-codegen
$ elm install elm/json
# manually replace "src" with "." in elm.json
$ cd ..
$ elm-codegen run

Broken import statements when local module uses import aliases

For example, this file:

module BadModuleNamedWith exposing (dummyDecoder)

import Json.Decode as JD


dummyDecoder : JD.Decoder String
dummyDecoder =
    JD.succeed ""

would produce Gen code containing:

{-| dummyDecoder: JD.Decoder String -}
dummyDecoder : Elm.Expression
dummyDecoder =
    Elm.value
        { importFrom = [ "BadModuleNamedWith" ]
        , name = "dummyDecoder"
        , annotation = Just (Type.namedWith [ "JD" ] "Decoder" [ Type.string ])
        }

which would then produce generated code that contains import JD instead of import Json.Decode.

I've added a test case to demonstrate: 3e7c055

image

Thanks for creating elm-codegen, it's fantastic! πŸ™

Elm.string does not escape characters

I just shot myself in the foot. I wrote something like

Elm.string "(\\a -> a)"

and got

"(\a -> a)"

which throws an error, because \a is not a valid character!

So what I would have expected was to get

"(\\a -> a)"

instead.

Missing parentheses for boolean operations

This code:

(Elm.Op.and (Elm.bool False)
    (Elm.Op.or (Elm.bool True)
        (Elm.bool True)
    )
)

Produces

False && True || True

instead of

False && (True || True)

Which drastically changes the meaning.

Missing qualifier when referring to a type using the Gen helpers

Hey! Thanks for the awesome tool, really loving it.

I think I found a minor bug. It results in generated code that has a compiler error because it references a type as Effect when it would need to be Effect.Effect to be valid (or expose the type from the import with import Effect exposing (Effect)).

How to reproduce:

I have this code in my codebase in app/Effect.elm

module Effect exposing (Effect(..), batch, fromCmd, map, none, perform)

{-| -}
none : Effect msg
none =
    None

{-| -}
type Effect msg
    = None
 -- | ...

I tell elm-codegen to generate bindings for this module with elm-codegen install app/ (so it gives me Gen.Effect).

It generates this definition:

none : Elm.Expression
none =
    Elm.value
        { importFrom = [ "Effect" ]
        , name = "none"
        , annotation = Just (Type.namedWith [] "Effect" [ Type.var "msg" ])

Which results in

import Effect

update : -- ...
    -> ( Model, Effect msg ) -- should be `Effect.Effect msg` (or import alias)

If I tweak this in the generated code, it results in correct, compiling output:

module Gen.Effect exposing -- ...

none : Elm.Expression
none =
    Elm.value
        { importFrom = [ "Effect" ]
        , name = "none"
        , annotation = Just (Type.namedWith [ "Effect" ] "Effect" [ Type.var "msg" ])
        }

I'm not sure if using Type.namedWith [ "Effect" ] "Effect" is the right fix, or if it should be using importFrom to get the right namespace there, but seems like it's one of those things I believe.

There's a reproducible case for this if you clone this repo and run these two commands: https://github.com/dillonkearns/elm-pages-3-alpha-starter#running-elm-pages-codegen-command, and then look at the resulting output file app/Route/User/Id_.elm.

Let me know if there's any other context I can provide here. Thank you!

Example for JSON decoders

Hi, and thanks for making elm-codegen! 😁

If I understood correctly, one of its goals is boilerplate or repetitive code generation, such as JSON codecs or encoders-decoders. However, It isn’t clear how to use regular Elm types to generate an encoder or decoder, and it would be really helpful to have this common use case in the docs.

Is it possible to add an example to the README.md?

Apply module import aliases in Elm.ToString

I would like to be able to present a code snippet that has module import aliases already applied, without needing to create an entire File's contents and then trim it down.

For example, if I want the following code snippet to show:

myIcon : Svg.Svg
myIcon =
    UiIcon.preview

assuming the generated code looks like this:

-- Copied from codegen/Gen/Nri/Ui/UiIcon/V1.elm
-- after running elm-codegen NoRedInk/noredink-ui
preview : Elm.Expression
preview =
    Elm.value
        { importFrom = [ "Nri", "Ui", "UiIcon", "V1" ]
        , name = "preview"
        , annotation =
            Just (Type.namedWith [ "Nri", "Ui", "Svg", "V1" ] "Svg" [])
        }

I believe I would need to do some mucking about with the result of the following in order to focus in on the part of the generated code that I care about.

    Elm.fileWith [ "My", "Module" ]
        { docs = \_ -> []
        , aliases =
            [ ( [ "Nri", "Ui", "UiIcon", "V1" ], "UiIcon" )
            , ( [ "Nri", "Ui", "Svg", "V1" ], "Svg" )
            ]
        }
        [ Elm.declaration "myIcon" preview
        ]
        |> .contents
        |> ... string trickery

It would be nice to be able to do:

Elm.ToString.expressionWith 
            { aliases =
            [ ( [ "Nri", "Ui", "UiIcon", "V1" ], "UiIcon" )
            , ( [ "Nri", "Ui", "Svg", "V1" ], "Svg" )
            ]}

and so forth instead.

Unnecessary Elm dependencies in generated project

When running elm-codegen init, the following elm.json file is generated.

{
    "type": "application",
    "source-directories": [
        "."
    ],
    "elm-version": "0.19.1",
    "dependencies": {
        "direct": {
            "elm/browser": "1.0.2",
            "elm/core": "1.0.5",
            "elm/html": "1.0.0",
            "elm/json": "1.1.3",
            "mdgriffith/elm-codegen": "4.0.0"
        },
        "indirect": {
            "elm/parser": "1.1.0",
            "elm/time": "1.0.0",
            "elm/url": "1.0.0",
            "elm/virtual-dom": "1.0.2",
            "elm-community/basics-extra": "4.1.0",
            "elm-community/list-extra": "8.6.0",
            "miniBill/elm-unicode": "1.0.2",
            "rtfeldman/elm-hex": "1.0.0",
            "stil4m/elm-syntax": "7.2.9",
            "stil4m/structured-writer": "1.0.3",
            "the-sett/elm-pretty-printer": "3.0.0"
        }
    },
    "test-dependencies": {
        "direct": {},
        "indirect": {}
    }
}

I don't believe that this project requires elm/html or elm/browser, and I believe they should be removed by default.

Support type and type alias constructors

I'd like to be able to use type and type alias constructors from the Gen folder when working with published Elm packages.

For example, if I had:

type Id
    = Id Int

type alias UserFlags =
    { id : Id
    , username : String
    }

I'd like to be able to use a reference to the Id and UserFlags constructors. Something like:

Gen.Json.Decode.map2 Gen.Example.constructors_.userFlags 
    (Gen.Example.constructors_.id (Elm.int 1)) 
    (Elm.string "username123")

that would produce:

Json.Decode.map2 UserFlags (Id 1) "username123"

Right now, I'm doing the equivalent of:

Decode.map2
    (\a b ->
        Elm.apply
            (Elm.value
                { importFrom = [ "Gen.Helper" ]
                , name = "UserFlags"
                , annotation = Nothing
                }
            )
            [ a, b ]
    )
    (Elm.apply
        (Elm.value
            { importFrom = [ "Gen.Helper" ]
            , name = "Id"
            , annotation = Nothing
            }
        )
        [ Elm.int 1 ]
    )
    (Elm.string "username123")

Install codegen/helpers/LocalFile.elm fails on run

Overview

Installing a local file inside of a directory fails when run is called.

This follows the pattern in the install help guide:

image

SSCCE project: https://github.com/absynce/elm-codegen-local-import-error.

Expected behavior

elm-codegen install codegen/helpers/LocalFile.elm creates helper. Then it runs with elm-codegen run.

Actual behavior

elm-codegen install codegen/helpers/LocalFile.elm creates helper. Then it errors with elm-codegen run.

To reproduce inside SSCCE project

elm-codegen run

Error

Error: ENOENT: no such file or directory, open 'generated/codegen/helpers/LocalFile.elm'

Full stacktrace

node:fs:585
  handleErrorFromBinding(ctx);
  ^

Error: ENOENT: no such file or directory, open 'generated/codegen/helpers/LocalFile.elm'
    at Object.openSync (node:fs:585:3)
    at Object.writeFileSync (node:fs:2155:35)
    at _loop_1 (/Users/absynce/.npm/_npx/be14e040090c2b5c/node_modules/elm-codegen/dist/run.js:521:16)
    at copyHelpers (/Users/absynce/.npm/_npx/be14e040090c2b5c/node_modules/elm-codegen/dist/run.js:540:9)
    at Command.<anonymous> (/Users/absynce/.npm/_npx/be14e040090c2b5c/node_modules/elm-codegen/dist/run.js:706:13)
    at step (/Users/absynce/.npm/_npx/be14e040090c2b5c/node_modules/elm-codegen/dist/run.js:71:23)
    at Object.next (/Users/absynce/.npm/_npx/be14e040090c2b5c/node_modules/elm-codegen/dist/run.js:52:53)
    at /Users/absynce/.npm/_npx/be14e040090c2b5c/node_modules/elm-codegen/dist/run.js:46:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/absynce/.npm/_npx/be14e040090c2b5c/node_modules/elm-codegen/dist/run.js:42:12) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: 'generated/codegen/helpers/LocalFile.elm'
}

System info:

node -v
v16.14.0

elm-codegen -V
0.1.0

Non-portable path in `elm.codegen.json` codegen-helpers.local.

When running

elm-codegen init

on Windows, everything works fine. It generates a path with correctly escaped backslashes into elm.codegen.json.

However, when a Unix-style path are included (E.g. change in the generated file codegen\\helpers\\ to codegen/helpers/), the path is silently ignored.

This can be seen by deleting codegen/Gen and running elm-codegen install. After that, codegen/Gen/Helper.elm is missing.

The main issue is: On Windows, a path like codegen/helpers/ should be interpreted as codegen\\helpers\\.

Less important: elm-codegen init should write codegen/helpers/ into elm.codegen.json.

This issue was discovered together with @dillonkearns.

Aliases in function type annotations change the generated code

When a function uses a type alias in its annotation, the generated code will use an Expression rather than the actual type.

That is, if I have a function

{-| -}
fWithoutAlias : { a : List Int } -> ()
fWithoutAlias _ =
    ()

The generated code will have the type annotation: fWithoutAlias : { a : List Int } -> Elm.Expression

but if my starting function is identical except that it uses an alias:

type alias Config =
    { a : List Int }


{-| -}
fWithAlias : Config -> ()
fWithAlias _ =
    ()

the generated code will have the type annotation fWithAlias : Elm.Expression -> Elm.Expression.

I expected the generated code to be same whether or not I referenced a type alias in the function signature.

Support for passing an indentation level to toString

When combining elm-codegen with elm-review you can end up with invalid indentation. E.g. given

{-| @generated-by_elm-review-codegen
-}
encodeTuple : ( Bool, Int ) -> Json.Encode.Value
encodeTuple foo = Debug.todo ""

and expecting the result of

encodeTuple : ( Bool, Int ) -> Json.Encode.Value
encodeTuple foo =
    case food of
        ( first, second ) ->
            Json.Encode.list identity
                [ Json.Encode.bool first, Json.Encode.int second ]

or possibly

encodeTuple : ( Bool, Int ) -> Json.Encode.Value
encodeTuple foo = case food of
                                  ( first, second ) ->
                                          Json.Encode.list identity
                                                  [ Json.Encode.bool first, Json.Encode.int second ]

but instead I get

encodeTuple : ( Bool, Int ) -> Json.Encode.Value
encodeTuple foo = case foo of
    ( first, second ) ->
        Json.Encode.list identity
            [ Json.Encode.bool first, Json.Encode.int second ]

Given that I have indentation information from elm-review it'd be nice to be able to do Elm.toStringWithIndentationOf range.start.column someExpression (or such).

`elm.codegen.json` local codegen-helpers requires `src\\` on Windows

Thank you for the library!

Likely related to #59, the docs show src/ as a way to include all your src folder. If I do this on Windows, elm-codegen runs without error, but doesn't actually generate any files.

image


However, if I've got a file in src called Foo.elm, 'local': [ 'src/Foo.elm' ] successfully generates Gen/Foo.elm.

In order for me to get all my src files generated, I need to use two backslashes:

{
    "elm-codegen-version": "0.5.0",
    "codegen-helpers": {
        "packages": {
            "elm/core": "1.0.5"
        },
        "local": [
            "src\\"
        ]
    }
}

Which works after a short processing delay. Note the backslash too.

image

Thanks again for the library!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.