Busy Developers Guide: CoffeeScript

Please note that these instructions are for busy developers, and assume that you are one. If so, this should help, if you’re not, these may not. Sorry about that. Below are the steps I used…

  1. First get npm (the node package manager).
  2. You’ll find a one line install such as this or similar: curl http://npmjs.org/install.sh | sh
  3. Next CoffeeScript: npm install -g coffee-script (Leave off the -g if you don’t wish to install globally.)
  4. Assuming that went well you should be able to type “coffee” on the command line and see a "coffee>" prompt.
  5. Pat yourself on the back and start developing! But wait, a little more structure might help… You can skip the steps below and check out the repository.
  6. Create a new folder and get it set up as a repository. For me that looks something like this: mkdir ~/code/learning_coffeescript; cd ~/code/learning_coffeescript; git init;
  7. Create some files a bit of structure. A top level public directory and src directory. Inside public I created a lib dir and an index.html file.
  8. The index.html file contains a base html 5 template, and in my learning case it included a line pointing to the hosted jquery.js lib, and our newly compiled javascript file (yeah, I know, patience… I’ll get to it in a minute.)
  9. Back in the terminal, at your project root, type coffee -o public/lib -cw src which will compile all the CoffeScript files written in src into javascript in lib. It is “watching” the src files timestamps so if you update and save a file it will recompile.
  10. Assuming you’ve got everything wired up correctly, you can fire up a browser, open the index.html file and go to town.
  11. If you want to get snazzy you can rackup file_server.ru -p 1111 and the project will run under a basic Rack file server.
  12. If you wish to be all hip and edgy you can download and install Pow, symlink your local clone of the repository and develop to your hearts content.

Feel free to make pull requests, or send me issues, updates, or notes. I’m sure I have a lot to learn about CoffeeScript how best to integrate it with jQuery, etc. In the end though, I’m enjoying the syntax. It was just not clear how to get a project going. Next I’ll be looking at testing…