Converting Gulp into Coffee

I originally wrote all of my Gulp stuff using vanilla Javascript for one reason, and that was because from what I had seen, it was somewhat annoying to use Gulp with CoffeeScript, at least out of box.

I had a friend show me a way to easily integrate CoffeeScript into Gulp, and I’m not looking back.

If you didn’t notice before, I use a modular approach to organizing my Gulp, so I have quite a few JS files to convert. Needless to say, I didn’t want to have to do it manually, so I found some tools to help automate.

Here’s how quickly you can do it:

1) Install JS2Coffee.

shell
1
npm install -g js2coffee

2) Install this awesome script to convert all of your Javascript into Coffee recursively within a directory.

shell
1
2
3
$ touch /usr/local/bin/all2coffee
$ vim /usr/local/bin/all2coffee
# (...insert code and save file, and set permissions)

3) Convert all of your Javascript files and Gulpfile into CoffeeScript, then remove all the JS.

shell
1
2
3
$ cd gulp/
$ all2coffee
$ rm -rf **/*.js

4) Add a simple Gulpfile.js with this in it:

gulpfile.js
1
2
require('coffee-script/register');
require('./gulpfile.coffee');

You should be good to go!