Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build tools in Elm #2

Closed
wants to merge 2 commits into from
Closed

Build tools in Elm #2

wants to merge 2 commits into from

Conversation

eeue56
Copy link
Owner

@eeue56 eeue56 commented Nov 25, 2015

Here's a crazy idea:

What if everything was written in Elm?

I mean, we already have

  • Full client side support (JS, html, stylesheets)
  • Server support (with node!)
  • Database support (with node bindings!)

Why not go one more, and add build tools for Elm, in Elm too?

How do we do that? By abusing Elm, of course!

Firstly, there are some rules to make this work:

  • Any Native code will be injected into the output file if the Native module is imported anywhere
  • The Native code will be injected as found in the file
  • Native code is bound before compiled Elm code
  • timeouts make thing run later.
  • ports get run by default if you include the file as Elm.worker(Elm.module)

With this in mind, it's pretty easy to make Elm output a file that can run itself. Or one that can run another file!

Add this little guy to the end of the Native module and watch what happens

setTimeout(function() {
    console.log("starting elm..");
    Elm.worker(Elm.Bootstrapper);
, 1000);

At the moment, this file will -

  • Run itself
  • Compile other modules
  • Run the module it just compiled

In the real world, there's not really a case for this to be used. This is just here as an example - if you want an Elm project that can replace any other tool you have except for node, here's the guy to gun for.

@avh4
Copy link

avh4 commented Jan 20, 2016

FYI, here's an old tool I wrote that's half written in Elm: https://github.com/avh4/elm-compile-html

I think it would be great to make it easy to write command line tools in Elm.. I had a few ideas around that before starting on elm-format, but I haven't gotten back to them yet.

@eeue56
Copy link
Owner Author

eeue56 commented Jan 20, 2016

This change makes it function and bootstrap like a standard node.js "binary" file, so it effectively a command line app. I also thought about considering a port of elm-format to Elm, but for speed reasons it probably makes sense to be in Haskell right now

@eeue56 eeue56 closed this Aug 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants