Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script/App that automatically compiles and compresses js files as you save

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.

like image 522
Jayson P Avatar asked Jul 18 '10 07:07

Jayson P


1 Answers

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/
like image 200
Impiastro Avatar answered Nov 05 '22 14:11

Impiastro