Jayson P
Jayson P

Reputation: 91

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.

Upvotes: 9

Views: 624

Answers (4)

Mark Northrop
Mark Northrop

Reputation: 2623

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/

Upvotes: 0

gaRex
gaRex

Reputation: 4215

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

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

Upvotes: 0

Impiastro
Impiastro

Reputation: 858

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/

Upvotes: 3

Cheery
Cheery

Reputation: 25423

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.

Upvotes: 0

Related Questions