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:
- Get the request URL: "http://localhost:9000/?plugins=footnote,googlemap"
- Parse the URL into it's respective parts: hostname, port, query
- Parse the Query String into an object: { "plugins": "footnote,googlemap" }
- Split variables on commas: { "plugins": [ "footnote", "googlemap" ] }
- Build the requested Popcorn bits into one large string using Node's FileSystem module
- Minify the built script using uglify-js
- Return the compiled code as "text/javascript"
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 ):
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:
- http://cade.pdbt.jit.su/?plugins=text
- http://cade.pdbt.jit.su/?modules=player&players=youtube,vimeo
- http://cade.pdbt.jit.su/?modules=parser&parsers=parserSBV&plugins=subtitle
- http://cade.pdbt.jit.su/?modules=player,parser,timeline-sources&players=youtube,vimeo&parsers=parserSSA,parserJSON&plugins=text,googlemap,subtitle
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
I've created a GitHub repo for this project, you can find it at github.com/cadecairos/PopcornDynamicBuildTool