There are a lot of poor souls that are forced to use Windows as an OS for their daily development job. I’m one of them. I heard even of people enjoying working on Windows There is one thing in common for them: Using cutting edge tools like CoffeeScript, node.js and others isn’t working easily out of the box most of the time. But in case of CoffeeScript there is good news. Since the release of Node.JS 0.6 with native windows support everything is working pretty fine. Here is what you will need to do to get it working.
Installing Node.JS
The best way using CoffeeScript is the installation via Node.js. The setup of Node.js can easily be done with the new Windows-Installer package that is available on the project site. There is nothing special here. After node.js is installed you will need to setup the node.js package manager (npm). You willneed to have a Git-Client installed on your machine. The best you can get is msysgit which brings a git bash console. Please make sure you have version 1.7.6 or newer installed on your PC. Open up a Git-Bash console and change to the folder you want to install npm (C:\Program Files for example). After that execute the following three commands:
[crayon lang=sh]> git config –system http.sslcainfo /bin/curl-ca-bundle.crt
> git clone –recursive git://github.com/isaacs/npm.git
> cd npm
> node cli.js install npm -gf
[/crayon]
You have now the node.js package manager installed.
Installing CoffeeScript
Installing CoffeeScript is now a piece of cake. Just use the following command:
[crayon lang=sh]> npm install -g coffee-script[/crayon]
The -g switch ensures that your CoffeeScript installation is available system-wide. If everything went right you can now start the CoffeeScript commandline tool from the console.
If you need tutorials or reference material for CoffeeScript here is what I found useful:
- The Little book of CoffeeScript
- Peepcode Screencast for CoffeScript
- CoffeeScript book from Pragmatic Bookshelf
Using Coffee-Script with Assetic
Working with Coffee-Script and the commandline compiler leads to uncomfortable development process. But there is light at the end of the tunnel. As with all assets Assetic will be of great help when using Coffee-Script files in your Symfony project. The AsseticBundle is part of the Symfony2 Standard Edition so there is no need to install anything. You just have to do some configuration work ahead. This is done in the app/config/config.yml file. There you have to add a filter for CoffeeScript.
[crayon]
assetic:
filters:
coffee:
[/crayon]
By default this filter is looking at fixed folders for the bin files of CoffeeScript and node.js. These paths are unix-ones. So we need to configure the paths, so they correspond with your installation folders.
[crayon]
assetic:
filters:
coffee:
bin: c:/nodejs/bin/node.exe
node: c:/npm/bin/npm.exe
[/crayon]
From now on there is no difference in using the CoffeeScript files with Assetic compared to unix systems. Here is how to use them in Twig-Templates.
[crayon lang=php]
{% javascripts filter=”coffee”
‘@AcmeHelloBundle/Resources/js/arabica.coffee’
%}
{% endjavascripts %}
[/crayon]
If you need more infos on how to use CoffeeScript with Assetic take a look at the Blog of Richard Miller