elm-spa/cli
Ryan Haskell-Glatz 61f9988e79 new cli works
2019-10-31 15:32:08 -05:00
..
src dat aint be a decoder tho 2019-10-31 15:28:09 -05:00
elm.json write generator in elm because hehehe 2019-10-26 15:51:06 -05:00
index.js new cli works 2019-10-31 15:32:08 -05:00
README.md new cli works 2019-10-31 15:32:08 -05:00

the cli tool

you could type everything out... or...

usage: elm-spa <command> [options]

commands:
  help                      prints this help screen
  build [options] <path>    generates pages and routes
  init [options] <path>     scaffolds a new project at <path>

options:
  --ui=<Html|Element>       what your \`view\` returns (default: Html)

so the package makes wiring things up consistent

And you know what loves consistency? Computers!

So if you don't want to type out this:

type Model
  = Foo Foo.Model
  | Bar Bar.Model
  | Baz Baz.Model

type Msg
  = Foo Foo.Msg
  | Bar Bar.Msg
  | Baz Baz.Msg

init route_ =
  case route_ of
    Route.Foo route -> foo.init route
    Route.Bar route -> bar.init route
    Route.Baz route -> baz.init route

update msg_ model_ =
  case ( msg_, model_ ) of
    ( FooMsg msg, FooModel model ) -> foo.update msg model
    ( BarMsg msg, BarModel model ) -> bar.update msg model
    ( BazMsg msg, BazModel model ) -> baz.update msg model
    _ -> Page.keep model_

bundle model_ =
  case model_ of
    FooModel model -> foo.bundle model
    BarModel model -> bar.bundle model
    BazModel model -> baz.bundle model

It was pretty easy to make a script to type that for you:

elm-spa generate

And it will look at the files in your src/Pages folder:

src/
  Pages/
    Foo.elm
    Bar.elm
    Baz.elm

And even generate the routes based on the module name:

-- routes
/foo -> Foo.elm
/bar -> Bar.elm
/baz -> Baz.elm

Hooray!

This CLI tool just benefits from the consistent API the package uses.

If you'd rather use ryannhg/elm-spa without the CLI tool- that's cool with me! 😎