Вопрос

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.

Это было полезно?

Решение

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.

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top