Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coffee script compilation

Tags:

I'm looking for simplest possible way to automatically recompile coffee scripts into JS.

Reading documentation but still having troubles to get exactly what I want.

I need it to watch folder src/ for any *.coffee files modifications and compile them into concatenated javascript file into lib/something.js.

Somehow can't combine watching, compiling and concatenating together. :/

like image 513
Arnis Lapsa Avatar asked Feb 20 '11 23:02

Arnis Lapsa


People also ask

Is CoffeeScript still a thing?

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.

What is a .coffee file?

JavaScript file written in CoffeeScript, a programming language that compiles and transcompiles to JavaScript; saved in a text format and contains code that is similar to JavaScript, but modified to be more readable. CoffeeScript's aim is to enhance JavaScript's brevity and readability.


1 Answers

The coffee script documentation provides an example for this:

Watch a file for changes, and recompile it every time the file is saved:

coffee --watch --compile experimental.coffee 

If you have a particular script you want to execute, you could use the linux command dnotify: http://linux.die.net/man/1/dnotify

dnotify --all src/ --execute=command 

Edit: I had some problems with the --execute part of dnotify - might be a bug, but this is what I got working:

dnotify --all . -e `coffee -o lib/ --join --compile *.coffee` 

That executed the compile command each time a file was modified.

If you append the command with an ampersand, like this:

dnotify --all . -e `coffee -o lib/ --join --compile *.coffee` & 

it will be started in a separate process. To get the process ID, you can use this:

ps ux | awk '/dnotify/ && !/awk/ {print $2}' 

And then, you can kill the process by using something like this:

kill `ps ux | awk '/dnotify/ && !/awk/ {print $2}'` 

But if that's your objective (to kill by process name), you can do it in a simpler way by using:

killall dnotify 
like image 77
arnorhs Avatar answered Oct 30 '22 14:10

arnorhs