Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Join multiple Coffeescript files into one file? (Multiple subdirectories)

I've got a bunch of .coffee files that I need to join into one file.

I have folders set up like a rails app:

/src/controller/log_controller.coffee
/src/model/log.coffee
/src/views/logs/new.coffee

Coffeescript has a command that lets you join multiple coffeescripts into one file, but it only seems to work with one directory. For example this works fine:

coffee --output app/controllers.js --join --compile src/controllers/*.coffee

But I need to be able to include a bunch of subdirectories kind of like this non-working command:

coffee --output app/all.js --join --compile src/*/*.coffee

Is there a way to do this? Is there a UNIXy way to pass in a list of all the files in the subdirectories?

I'm using terminal in OSX.

They all have to be joined in one file because otherwise each separate file gets compiled & wrapped with this:

(function() { }).call(this);

Which breaks the scope of some function calls.

like image 922
kush Avatar asked Jan 01 '11 18:01

kush


1 Answers

From the CoffeeScript documentation:

-j, --join [FILE] : Before compiling, concatenate all scripts together in the order they were passed, and write them into the specified file. Useful for building large projects.

So, you can achieve your goal at the command line (I use bash) like this:

coffee -cj path/to/compiled/file.js file1 file2 file3 file4

where file1 - fileN are the paths to the coffeescript files you want to compile.

like image 70
benekastah Avatar answered Oct 18 '22 20:10

benekastah