Search code examples
javascriptnode.jscoffeescriptjake

How do you compile CoffeeScript in a Jakefile?


I would like to create a Jakefile which compiles some CoffeeScripts to install a NodeJS application.

How do you do that?

I tried with: https://gist.github.com/1241827

but it's a weak approach, definitely not classy.

Any hints?


Solution

  • Approx snippet I have used:

    var fs = require('fs')
    var coffee = require('coffee-script')
    
    // If you'd like to see compiled code..
    // console.log(coffee.compile(fs.readFileSync('coffee.coffee')))
    
    // ..otherwise
    fs.writeFileSync('output.js', coffee.compile(fs.readFileSync('input.coffee')))
    

    ..assumes you have the coffee-script node module installed, of course.

    Translated from this Cakefile of mine.