elm-lang / elm-make

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

This creates a JavaScript file, not an HTML file: elm-make Main.elm --output=main.htm #14

Closed jhftrifork closed 9 years ago

jhftrifork commented 9 years ago

I installed the latest version of Elm via cabal. When I copy-paste this "hello world" program into a file Main.elm and then run

elm-make Main.elm --output=main.htm

as instructed in the README except with a .htm extension, I get a file at main.htm which looks like:

var Elm = Elm || { Native: {} };
Elm.Basics = Elm.Basics || {};
Elm.Basics.make = function (_elm) {
   "use strict";
   _elm.Basics = _elm.Basics || {};
   if (_elm.Basics.values)
   return _elm.Basics.values;
   var _op = {},
   _N = Elm.Native,
   _U = _N.Utils.make(_elm),
...
                      ,line: line
                      ,leftAligned: leftAligned
                      ,rightAligned: rightAligned
                      ,centered: centered
                      ,justified: justified
                      ,plainText: plainText
                      ,markdown: markdown
                      ,asText: asText};
   return _elm.Text.values;
};

This is JavaScript, not HTML.

It appears that the tool has different behavior depending on the file extension of the filepath passed in the output argument. IMO, this behavior difference should be toggled by a separate flag, e.g. --outputtype=html.

jhftrifork commented 9 years ago

(Correction: I used the file extension .htm. This appears to not be recognised as a valid HTML file extension.)

jhftrifork commented 9 years ago

This is the code in question: https://github.com/elm-lang/elm-make/blob/748d774d9e3ec8d0163652dd3e118544d66370d3/src/Generate.hs#L48

The policy is that if the output option ends with ".html", we generate HTML output at that path; otherwise, we generate JavaScript output at that path.

I would change this policy to one of these policies:

  1. If the output option ends with ".html" or ".htm", we generate HTML output; otherwise, we generate JavaScript output.
  2. If the output option ends with ".html", we generate HTML output; else if it ends with ".js", we generate JavaScript output; otherwise, we raise an error.
  3. We generate content determined by a content-type command-line option which can be set to either "html" or "javascript".
evancz commented 9 years ago

This will be resolved in the next release. We will only permit files that end with .html and .js. If you want other names you can rename the file afterwards.