views:

176

answers:

7

How can I try CoffeeScript on Windows?

The installation instructions are only for *nix: http://jashkenas.github.com/coffee-script/#installation

EDIT:

I don't think I need node.js -- I am just writing javascript for web pages, (using some jQuery, etc)...So all I really want is simple way to write CoffeeScript and "compile" it down to JavaScript. Isn't there a Ruby program that would do it? Or even better, a windows exe? (i dont use ASP.NET either...i use Python/Django)

FINAL EDIT: Thanks for the help -- In the end I installed VirtualBox and created a virtual Linux machine which I now use to program coffeescript with node.js. (It was surprisingly easy to start using VirtualBox -- easier than doing the Cygwin thing). I run jEdit (for which you can get a CoffeeScript syntax highlighter) and I put the corresponding js file side-by-side with the coffeescript file. When I compile the coffeescript to js, the editor automatically re-loads the new javascript, which allows me to check that it has compiled the way I expect (which is a good thing while learning the coffeescript syntax).

+3  A: 

Hi Nick. Node.js runs on Cygwin these days, so that's probably your best bet with getting CoffeeScript running on Windows. I'd try that first.

If you have a different preferred JavaScript runtime, you can probably use the prebuilt-compiler (extras/coffee-script.js). For example, if you include that script on a webpage, you can call

CoffeeScript.compile(code);

... to get back the compiled JavaScript string.

jashkenas
I don't think I need node.js ( see my edit )....but your "compile" suggestion is interesting! How exactly would that work? I would serve up both my coffeescript, and the compiler, and the browser would compile it down to regular javascript, and then run it? That would be cool! But how do you make that happen? Are there examples of how to do this? Would I be able to see the generated javascript?...and Debug it with FireBug?
Nick Perkins
Node.js is recommended. You can compile inline CoffeeScript in the browser, by including the compiler, and writing your code in a "text/coffeescript" tag. It's all eval'd that way, so you can't see the generated JS or debug it with Firebug... which is a long-winded way of explaining by pre-compiling it with Node.js is the best way to develop. For the details, see:http://jashkenas.github.com/coffee-script/#scripts
jashkenas
So I am going to need Cygwin to actually develop in CoffeeScript? That's ok, but I wish it was easier for a Windows user to get started. CoffeeScript looks really cool, I would switch all my javascript programming over to coffeescript if there was an eclipse plug-in that compiled on-the-fly like the excellent "Try CoffeeScript" interactive compiler/interpreter on the CoffeeScript website. That would be wicked!
Nick Perkins
+1  A: 

If you want to use CoffeeScript in an Asp.NET application then you can use this Http Handler to serve compiled CoffeeScript.

liammclennan
As is mentioned in the comments on this HttpHandler, by Liam, it's quite a hack, but a pretty ingenious one! It should hold us over until someone ports NodeJS to windows
PandaWood
+1  A: 

You can use a command-line version of CoffeeScript by installing Ruby on Windows and then installing the CoffeeScript Gem

After that, the command-line is available eg 'coffee bla.coffee' - to compile your CoffeeScript down to javascript.

The only disadvantage doing it this way (not using nodejs) is that the Ruby version of CoffeeScript is restricted to version 0.3.2 - the last version written in Ruby before it was moved over to nodejs.

However, I still use the Ruby version of CoffeeScript in my current employment and my personal web page and I don't see much of a problem as this version of CoffeeScript is quite mature and most of the features listed on the CoffeeScript website can be used.

PandaWood
A: 

The easiest way to build JavaScript files from CoffeeScript files is to use XCoffeeScript, a simple windows tool that requires no complicated installs: http://bit.ly/9wplmE

To compile one file do:

XCoffeeScript --file yourfile.coffee

(you'll get yourfile.js)

To compile a lot of files at once in a directory do:

XCoffeeScript --dir yourdir

Kyle C. Quest
Your "XCoffeeScript" would seem to be a simple solution (being a windows exe) but there's no project or openness about the source - the link you've provided is a direct link to a .zip file. How can we get the latest version? or verify which version of cofeescript it's built against?
PandaWood
+2  A: 

You could also use jcoffeescript as a command-line solution.

It uses a java-based javascript engine - (the same one used by Firefox) and wraps up the task of compiling the coffee-script.js file produced by the coffeescript project. This allows it to run the coffee-script compiler as a java program.

The command line I use (on Windows) looks like this:

type | foo.coffee java -jar jcoffeescript-0.9.2.jar > foo.js

You will need to download & build the Java source code (use IntelliJ Community Edition to avoid downloading ANT as well perhaps?).

I now use jcoffeescript in place of the Ruby solution (another answer here), because this allows me to keep up with the latest coffeescript project version.

PandaWood
A: 

This solution works well.

liammclennan
A: 

You can look at this article, where I described how to compile coffee-scripts by Node.js, and Cygpath on Windows without virtual machines.

Mikhail Nasyrov
Yay: Node for Windows! ( http://node-js.prcn.co.cc/index.html )
Nick Perkins
Thanks for the article, but the significant thing is that someone has build a Node for Windows! ( http://node-js.prcn.co.cc/index.html ) by bundling some cygwin dlls But who has done this? is it "official"? does it do everything that the Linux version does? It does seem to work!
Nick Perkins