I’m not going to describe here how the Compiler works in detail. In short words, it scans your files looking for comments in a specific, JSDoc-like format and makes use of them. There is also a tool called calcdeps which is a linker – it scans files for dependencies and helps compiler to merge files in the correct order.
To make it even more fun, I decided to write a Makefile which will be a final jaw-dropper.
PYTHON = python CALCDEPS = ~/closure/closure-library-read-only/closure/bin/calcdeps.py CLOSURECOMPILER = ~/closure/compiler.jar all: $(PYTHON) $(CALCDEPS) -p src -i src/init.js -o compiled -c $(CLOSURECOMPILER) > scripts/ai-bot-compiled.js
It works like charm, “make” is compiling all required files from src folder, merging them into one.
I was surprised how easy it was – calcdeps takes a path (-p) where you store all your libraries and an initial file (-i). The rest is based on goog.require(classname) and goog.provide(classname) calls from files. I barely used Google Closure Tools so far, but the Compiler is absolutely great!