9

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.

Jacob Relkin
  • 161,348
  • 33
  • 346
  • 320
Jayson P
  • 91
  • 1
  • Somewhat relevant, although you SHOULD specify OS.. http://stackoverflow.com/questions/3274334/how-can-i-watch-a-file-for-modification-change – meder omuraliev Jul 18 '10 at 07:45
  • Mac OS X. thanks meder. This is a good start. I'm looking for an app/script that watches a specific folder for when any file in that directory is modified. – Jayson P Jul 18 '10 at 08:01
  • Compiling JavaScript? I'm behind the times. – Matt Ball Jul 29 '10 at 15:13
  • @Bears: It's just a catchy name for a compressor with some garbage removal. I tend to call it Google Closure Compressor – user123444555621 Jul 31 '10 at 13:53
  • It does do a bit more than compress your JS. It also checks for compile-time errors. But it is true it's not what you would typically think of as a compiler since it compiles down to JS and not to assembly, byte code, or some other language. – Ben McCann Aug 02 '10 at 02:28

4 Answers4

3

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
  • 848
  • 6
  • 8
0

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
  • 24,645
  • 16
  • 59
  • 83
0

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

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

gaRex
  • 4,144
  • 25
  • 37
0

Fileconveyor is a Python script that watches and processes files, and can even upload them automatically.

I'd recommend checking out the website to see if it's something that might help you: http://fileconveyor.org/

Mark Northrop
  • 2,613
  • 1
  • 20
  • 21