Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoffeeScript compiler API

I am working in CoffeeScript (writing a Cakefile). I would like to compile some other CoffeeScript files, à la

coffee -o lib -c src

I could launch the above command in a child process, but this approach has cross-platform issues and makes error handling difficult. I'd much rather use an API.

I'd be happy to use the exact functions from command.coffee, but I can't work out how.

Addendum: I see require('coffee-script').compile, which compiles a string to another string. That would still leave me to do the grunt work of looping over files and subfolders and writing the output.

like image 851
Colonel Panic Avatar asked Mar 28 '12 21:03

Colonel Panic


People also ask

What does CoffeeScript compile to?

CoffeeScript. CoffeeScript is a little language that compiles into JavaScript. Underneath that awkward Java-esque patina, JavaScript has always had a gorgeous heart.

Is CoffeeScript obsolete?

As of today, January 2020, CoffeeScript is completely dead on the market (though the GitHub repository is still kind of alive).

Is CoffeeScript better than JavaScript?

"Easy to read", "Faster to write" and "Syntactic sugar" are the key factors why developers consider CoffeeScript; whereas "Can be used on frontend/backend", "It's everywhere" and "Lots of great frameworks" are the primary reasons why JavaScript is favored.

Is CoffeeScript easy to learn?

CoffeeScript is a lightweight language that compiles into JavaScript. It provides simple and easy to learn syntax avoiding the complex syntax of JavaScript.


1 Answers

The API you're looking for is in coffee-script.coffee. It exports a compile function that does what it says on the tin.

To use command.coffee's run function directly you'd have to first overwrite process.argv with the options you would have passed on the command line.

like image 102
Jordan Running Avatar answered Sep 23 '22 15:09

Jordan Running