Upgrading Popcorn's Build Tool

Last night I made something really cool using Node.js. Node.js is a development platform for building applications using JavaScript. I've never built something before using it, but I decided to give it a shot. At first I had no idea what to create, but I eventually realized I should just stick to what I know best: Popcorn.

There's a ticket in Popcorn's issue tracker that requests a "dynamic build tool". This build tool would be a node app that will accept a set of parameters in query string format. The parameters will detail what bits of Popcorn that you want ( plugins, players, modules, etc ), build the script, and return it for use.

I looked at that ticket and knew that it was the perfect candidate. The first thing I did was familiarize myself with the API. I made the standard "Hello World" server, which simply outputs hello world to the browser on a request. From there, I Identified what modules I needed to get my task done, and built my app from there.

It was surprisingly easy to visualize what needed to be done. I identified the steps that would be taken on each request:

  1. Get the request URL: "http://localhost:9000/?plugins=footnote,googlemap"
  2. Parse the URL into it's respective parts: hostname, port, query
  3. Parse the Query String into an object: { "plugins": "footnote,googlemap" }
  4. Split variables on commas: { "plugins": [ "footnote", "googlemap" ] }
  5. Build the requested Popcorn bits into one large string using Node's FileSystem module
  6. Minify the built script using uglify-js
  7. Return the compiled code as "text/javascript"
Using these steps as my guide, I came up with a 0.1 version of the new "Popcorn Dynamic Build Tool" ( sucky name, I know... sue me. ).

Yesterday I found a really cool product that just entered public beta: nodejitsu. Nodejitsu provides its clients with scalable node.js hosting. The company provides free accounts that allow you development space for creating apps. I've uploaded my app to test it ( It won't be there forever, sorry. I'll link the repository below ):

http://cade.pdbt.jit.su/

Hitting that URL will return you just the Popcorn.js core. Appending a query string to it will return you the pieces you request. Here's a few examples of how it should look:

The idea behind the app is to drop these URL's into script tags and your JavaScript will be sent to you every time. Its actually pretty awesome.

There's several things that need to be added for this to become a truly awesome filled app. Here's a list of things I'll be adding on my free time ( credit is due to Bobby Richter for bringing up some of these features ):

  • Option for minified or unminified code
  • Option to specify version number
  • Option to set debug flag on or off
  • Shorthand options for common build types (complete, all plugins, etc) - could be paired with common Popcorn Maker template requirements, for example.
  • Caching of different request combinations, to eliminate redundant builds
Eventually, I'll probably end up working on a new build tool for popcornjs.org that will build users a custom link to the build of their choice.

I've created a GitHub repo for this project, you can find it at github.com/cadecairos/PopcornDynamicBuildTool