r26D

Plunk It!

I’m working on a project (which I will hopefully get to announce shortly) that involves a lot of JavaScript. In the process of doing research, I discovered Plunker. It is similar to JSFiddle. The main differences are - it handles multiple files (which is awesome). It is also completely open source (which is even more awesome!).

Even spending just a little time with it made me realize what a great tool it was for working with code. The only problem I had was that I needed to be able to work on code locally, but I wanted to be able to share that code on Plunker. It was especially important to me that I be able to make local changes and have the sync up. Since if you’ve ever written code you know that it will keep changing on you. So the last thing I wanted to have to do was some kind of a manual process to repost the content.

I spent some time over the weekend trying to figure out how to make it do what I wanted. I tried to run it locally, but I hit a problem that I still haven’t sorted out. I ended up learning that there is enough of an API built into Plunker that I could build my own script to do the posting.

The first hurtle I hit was oAuth. Plunker doesn’t do it’s own authentication. It outsources it to GitHub. You log in to your GitHub account and grant access to Plunker. That means that Plunker isn’t responsible for managing your account. The downside is that it makes it a lot more complicated to authenticate in to Plunker.

I spent a lot of time trying to build my own path in to the oAuth. I did a lot reading and made zero progress. Then I noticed something. Using the Chrome JavaScript console, I was able to see what GitHub was posting to Plunker to tell it that I was authenticated. I copied down the hash that was provided. Currently, GitHub doesn’t time out these authentication tokens so my cache just works.

Now that I could authenticate as me, I could get back to working out the details. Long story short, I ended up building a ruby gem that handles all the details. It is called Plunk It. I’ve released it as a gem, and open sourced it. It doesn’t just handle getting your initial files up to Plunker. It can detect changes in your code and push them up as well.

Now I was able to build up a Rakefile in my project that handles all the details of pushing up the code and keeping it in sync.

So if you want to share JavaScript - this is a really slick way to do it.