Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
154 views
in Technique[技术] by (71.8m points)

javascript - Coffee script compilation

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. :/

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...