html-to-elm
html-to-elm copied to clipboard
Making a command line tool for html-to-elm
Hey, any thoughts on making a command line tool so that it can be used like babel?
@rajatvijay did you found a CLI version of html2elm?
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.
As a first step into this path I created this PR #24