Google Closure and How to Create a Batch File for Running ClojureBuilder

Learn how to create a batch file on Windows to use the Google Closure compiler.

Hoping this will save someone time in the future; whether the future is bright and shiny… or robotic apocalypse. One of the relatively few issues I’ve had with Google Closure was moving from calcdeps (I think that’s what it was called) to ClosureBuilder was setting up a batch file to run it. With calcdeps, it was mostly just naming a bunch of folders, and it did the rest. When I moved to ClosureBuilder, it wasn’t that easy. At first I panicked, and promptly jumped through a second story window, then I decided getting used to the new compiler is healthier in the long run. Turns out that even if ClosureBuilder expects actual namespaces to include, it’s better in the end as it makes it much easier to include/uninclude a particular namespace incase there’s a need to pick and choose. Here’s an example of the batch file I created to compile a “live” (Not test”) version:

python c:/lib/closure/closure-library/closure/bin/ ^
//Optional if you are running the 32 bit version of jvm/jre
--jvm_flags="-d32" ^
//This is where all the closure files exist
--root="c:/lib/closure/closure-library/" ^
//This is the folder in the project that has all the JavaScript files.
--root="content/script/live/" ^
//Here are the namespaces in that JavaScript folder that I want to include
--namespace="src.base.helper.arrayHelper" ^
--namespace="src.base.helper.constants" ^
--namespace="src.base.helper.domCreation" ^
--namespace="src.base.helper.domHelper" ^
--namespace="" ^
--namespace="src.base.control.gridBuilder" ^
--namespace="src.base.control.pager" ^
--namespace="" ^
--namespace="" ^
--namespace="" ^
--output_mode=compiled ^
--compiler_jar="c:/lib/closure/compiler.jar" ^
//This is optional if you want the super duper minimized version on compile.
//  I typically don't use the simple version, because I had found issues where
//   it works with simple, but not advanced.
--compiler_flags="--compilation_level=ADVANCED_OPTIMIZATIONS" ^
//This is where you want to save the compiled result.  I've found that it is easier
//  put the batch file in the web root, and have it use a relative path rather than
//  having to give it a drive path like c:\web\something\somethingElse\content...
--compiler_flags="--generate_exports" > "content/script/live/final.js"
//I keep this here for when I have to be on a computer with the 32 bit version of 
//  jrm/jvm.
rem --jvm_flags="-d32" ^

As you can see, it’s actually not all that complicated.

Ruby, Sinatra, and static content (You know, JavaScript)

Sinatra: A quick look at how to set the default static content folder name to anything other than “public”.

Good news: If you were searching on how to server up static files with Sinatra, you’re in luck.

Bad news: I’m using Ruby…

As I stumble through the use of Sinatra (and to a lesser extent Ruby) one of the first issues I ran into was self loathing, followed by a need to have the server actually find my main JavaScript and CSS files. Well this is the current set up in a really poorly done folder rendition:

- content/script/live
 |-- final.js
- content/style/css
 |-- final.css
- view
 |-- main.html
- base.rb

Pretty simple.

At first main.html had what I thought would be the correct link to both:

  <link rel="stylesheet" href="content/style/css/final.css" type="text/css"/>
  <script type="text/javascript" src="content/script/live/final.js"></script>

Turns out, that wasn’t right. After a few attempts to get the server to actually do what it’s supposed to (and there by giving my powers of deduction too much credit), I went a huntin’.

So today I learned that Sinatra by default expects there to be a folder named “public” that would hold the /style, and /script folders. Go figure. Being stubborn as I am, I didn’t want to put them in a parent folder named ‘public’, I wanted it name ‘content’. Don’t hate. Note: the folder has to be on the same level as the file that was used to start the server.

So this is more than possible. Just takes one line it the base file (the one you used to start your server):

require 'sinatra'
require 'json'

set :bind, ''
set :public_folder, { File.join(File.dirname(__FILE__), 'content') } <--- HERE

Yes there are five lines… No the other four aren’t part of this problem… You done?

Ok so it’s now looking at that folder, but there’s still one more step. Remember those links?

  <link rel="stylesheet" href="/style/css/final.css" type="text/css" />
  <script type="text/javascript" src="/script/live/final.js"></script>

Just had to remove the content folder mention in the links, and everything is happy. Except me… because it’s Ruby.