elm-lang / elm-make

A build tool for Elm projects
BSD 3-Clause "New" or "Revised" License
175 stars 45 forks source link

Feature Proposoal: Format Flag for JS vs HTML output #177

Open maxsnew opened 7 years ago

maxsnew commented 7 years ago

Motivation

As a build tool for a web technology, elm-make is not just used directly by humans but also by build scripts that combine elm with programs written in other languages. The current interface is optimized for direct human interaction, which is a fine default but should be overridable for unforeseen use-cases. Specifically, elm make Main.elm --output=main.js parses the filename given in the --output option, meaning tools can't output to files that do not end in js or html.

Proposal: --format Flag

My proposal is to add a --format flag that would allow you to ignore the filename and declare the intended output format directly. Currently you would have 2 options: js,html but we can easily add more in the future if needed.

# write js output to main.js
> elm make Main.elm --output=main.js
# writes js output to main
> elm make Main.elm --format=js --output=main
# write js output to main.html
> elm make Main.elm --format=js --output=main.html

This change would be backwards-compatible and wouldn't affect any user not using the feature except in that it makes elm make -h longer.

Use Case: Output to stdout

One non-obvious side effect of this would be to partially solve https://github.com/elm-lang/elm-make/issues/39 at least on unix-like systems using /dev/stdout as a filename:

# prints js compilation to stdout
> elm make Main.elm --format=js --output=/dev/stdout

so this would make elm make much easier to use for scripting for the reasons lain out in that issue. I don't know enough about Windows to say for sure, but from some brief googling it looks like this would not solve #39 for them.

process-bot commented 7 years ago

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

maxsnew commented 7 years ago

In implementing this change and trying it out I now see that printing to /dev/stdout would only really work if we add a --silent option that suppresses other printing to stdout.

Looking into that, I see that this would require some changes to elm-package.