views:

123

answers:

3

I'm building a web site and have multiple js files all in one directory. When I save any one of the js files I want a script to run that will compile and compress all files using the google closure compiler jar.

Example from Google Closure Compiler README:

java -jar compiler.jar --js=in1.js --js=in2.js ... --js_output_file=out.js

Is there a shell script or app that does this? I'm looking for something similar to how http://incident57.com/less/ works for CSS.

A: 

Linux and Mac OSX have application interfaces that let you monitor filesystem changes.

I'm myself using linux so I'm familiar with inotify. Doing a script that compresses your files would be easy enough that I could do it for you from a feasible price.

For Mac OSX you can use FSEvents to get a same effect. Though you'll need to do it yourself.

If you wonder how to do this on windows.. Well nobody in his full senses would be using that system for software development.

Cheery
+1  A: 

In linux you can use the inotifywait command to listen for changes in a specific folder. This script can you give an idea:

#!/bin/bash

directory=$1

inotifywait -q -m --format '%f' -e modify -e move -e create -e delete ${directory} | while read line

do
    echo "doing something with: $line";

    # for example:
    # java -jar compiler.jar --js=in1.js --js=in2.js ... --js_output_file=out.js 
done

You can invoke this script specifying the "monitor" directory, in this way

./inotify.sh ~/Desktop/
Impiastro
A: 

If you use some eclipse-like IDE, you can create and set builder for this.

But your project should also has "Build Automatically" checkbox.

Alexander