html-to-elm icon indicating copy to clipboard operation
html-to-elm copied to clipboard

Making a command line tool for html-to-elm

Open rajatvijay opened this issue 7 years ago • 3 comments

Hey, any thoughts on making a command line tool so that it can be used like babel?

rajatvijay avatar Oct 09 '17 17:10 rajatvijay

@rajatvijay did you found a CLI version of html2elm?

nivertech avatar Oct 12 '17 17:10 nivertech

Hi, I don't have any plans to do this, but I think it's certainly quite achievable. Here is a rough guide of how to do it (if anyone else is willing to give it a shot):

  • Create node command line app using something like https://github.com/panosoft/elm-node-main.
  • Take in a filepath as an input to the Node program
  • Read the file, send the contents of the file to Elm through a port.
  • run the string through this function: https://github.com/mbylstra/html-to-elm/blob/master/elm-src/HtmlToElm/HtmlToElm.elm#L225
  • send the output of the function through a port back to the node app.
  • output the contents to stdout.

The parser is pure Elm, so there's no need to run it through Electron or headless Chrome or anything like that. Other elm to html projects I've seen leverage the browser's built-in html parser, which doesn't make them very portable.

mbylstra avatar Oct 14 '17 00:10 mbylstra

As a first step into this path I created this PR #24

groteck avatar May 15 '18 18:05 groteck