Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling coffee binaries

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.

like image 459
johngeorgewright Avatar asked Sep 17 '26 11:09

johngeorgewright


2 Answers

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.

like image 58
Colin Ross Avatar answered Sep 19 '26 02:09

Colin Ross


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.

like image 31
Larry Maccherone Avatar answered Sep 19 '26 00:09

Larry Maccherone



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!