0.0.3 • Published 7 years ago

elm-run v0.0.3

Weekly downloads
1
License
BSD-3-Clause
Repository
github
Last release
7 years ago

elm run

NOTE: not upgraded for 0.18 - I've since concluded that ports are a better way to do this in Elm. elm-test is a great example of a node-based Elm app that uses ports to guarantee safety.

Task-based bindings for running Elm in the console.

Inspired by elm-console

Inspired by IO

Inspired by IOSpec

Usage

Here's an interactive "Hello, World!" example:

import Run
import Stream.Writable as Run
import Stream.Readable as Run
import Task



type Model = Model

type Msg
    = Name String
    | Abort



(>>=) = Task.andThen


read : Cmd Msg
read =
    Run.stdin >>= Run.getLine
        |> Task.perform (always Abort) Name


write : String -> Cmd Msg
write name =
    Run.stdout >>= Run.putStrLn ("Hello, " ++ name ++ "!")
        |> Task.perform (always Abort) (always Abort)



init : ( Model, Cmd Msg )
init =
    ( Model, read )


update : Msg -> Model -> ( Model, Cmd Msg )
update msg _ =
    case msg of
        Name name ->
            ( Model, write name )

        Abort ->
            ( Model, Cmd.none )



main : Program Never
main =
    Run.program { init = init , update = update }

elm run operates on compiled elm files, which means the workflow looks something like this:

$ elm make --output main.js Main.elm
$ elm run main.js
World
Hello, World!

You can get the elm run command via NPM:

npm install -g elm-run

Your program ends once it is no longer waiting for Tasks to complete.

Tests

docker build -t elm-run .
docker run elm-run ./test/run-all.sh