Question

If I'm writing my entire project in CoffeeScript, how do I write my "binary" files?

#!/usr/bin/env coffee
# My program sits here

Then, once compiled, I loose the shebang:

// Generated by CoffeeScript 1.4.0
// My program sits here

I was hoping it would turn into something like:

#!/usr/bin/env node
// My program sits here

Is it possible? Or do I need to rethink how I'm working.

Was it helpful?

Solution

As you surmise, you probably want a script to help you add the necessary shebang line. I usually create a Cakefile task to do the necessary compilation and add the appropriate first line.

OTHER TIPS

The trick is to NOT put a .coffee extension on your "binary" file and to not compile it.

I also recommend that you not place any signficant logic in the binary. Rather, just have the binary kick off the full source.

In general, every one of my binaries sits in a /bin directory off the root of my project and it has these two lines only (like my CoffeeDocTest project on GitHub here):

#!/usr/bin/env coffee
require(__dirname + '/../src/coffeedoctest')

You'll also want to run chmod 755 <filename> on it to make it executable.

Look here for an example of how the main coffeedoctest.coffee starts off and handles command line options, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top