Tag Archives: compiler

Introducing nCoffeeScript: a CoffeeScript compiler for Windows

January 8, 2011 | Jason Kozemczak

The wonderful CoffeeScript turned 1 (dot 0) over the Christmas break. For those who haven’t heard of it yet, I highly recommend you visit the site and look/play around. You can even check out the amazing annotated source for it, courtesy of its primary developer, Jeremy Ashkenas. The documentation is incredible actually.

In case Coffeescript is new to you, it’s a language that looks a lot like the lovechild of Ruby and Python, and it just so happens to compile into Javascript. If you visited the link above, you’d learn that it compiles 1-to-1 into Javascript. CoffeeScript’s compiled output is well-formed and well-performing Javascript. I could go on, but it’s probably best just to go to the site; it’ll do a far better job demonstrating its awesome-ness.

Poor Windows Developers…

CoffeeScript’s command-line compiler is implemented using Node.js; the downside to that fact is that there’s no easy way for Windows developers to integrate CoffeeScript into new and existing web apps. Since CoffeeScript is actually written in Javascript, it can be compiled in the browser, but this isn’t a very practical in an automated build/deploymen environment. CoffeeScript can also be compiled “on the fly” in a client’s browser, but this solution is not a viable production-level option.

Another possible solution is to install Cygwin, compile Node.js, and then download/install CoffeeScript, but this path is long and difficult, and still makes compiling from Windows arduous.

nCoffeeScript to the Rescue

The obvious solution to this problem was to create my own path. As such, I’ve created nCoffeeScript, a CoffeeScript compiler written in .NET for Windows environments! The source can be found on Github. Get the source, build it, and try it out. Let me know what you like and what you wish you could do with it!

I consider nCoffeeScript to be at v0.1 sort of state. I spent a few hours the past two nights getting the main use cases working, but haven’t put that much time into just yet.

Under the covers, nCoffeeScript uses Mozilla’s Rhino. nCoffeeScript interfaces with Rhino using IKVM for Java/.NET interoperability. nCoffeeScript is inspired by jCoffeeScript in its use of Rhino to execute the compilation process in Javascript.

Right now, you can use nCoffeeScript to compile an individual CoffeeScript file; you can also pass it a directory, and nCoffeeScript will compile each CoffeeScript file in the directory into its own Javascript file. By default, nCoffeeScript will wrap the compiled Javascript in a safety function. This wrapper can optionally be left out using the “/nowrap” command-line option.

For more details, visit the Github repo! Hopefully this is one step toward making it trivial to leverage CoffeeScript in our web applications. I hope to follow up with a possible path to utilizing nCoffeeScript in ASP.NET builds/deployments.