1 min read


One of the benefits of building stateful client-side apps, is that you can make them independent from the rest of your backend, having a separate repository and deploy process. The advantages of this is that it keeps your backend and frontend decoupled, and was the principal point behind my article on using Rails as an API.

However, splitting JavaScript, CoffeeScript and CSS out from a Rails app can be tricky. You no longer have an automatic asset pipeline and compilation, or indeed a server.

I've been using a number of basic Rack scripts to manage my JavaScript projects, and recently bundled them up into a gem called Catapult. Catapult manages building new apps, compiling assets and serving them. The gem is built on-top of Sprockets, and comes with CoffeeScript, Stylus and CommonJS compilers out of the box, my usual work flow.

To be fair, there's no shortage of asset compilation libraries on GitHub, and I was a bit loath to reinvent the wheel. Having said that, the key principal behind Catapult is simplicity. It's suits my personal use-case perfectly, and customizing it is absolutely trivial.

Now let's explore some basic usage. To generate an app, use the new command:

$ catapult new myapp

  create  myapp
  create  myapp/assets/javascripts/app.js
  create  myapp/assets/stylesheets/app.css
  create  myapp/browser.json
  create  myapp/public/index.htm

$ cd myapp

Now you can start a catapult server:

$ catapult server

And open up the app in your browser. During deployment, you'll want to serve the files statically. You can write compiled files to disk using the build command.

$ catapult build

You can even watch the files for changes, and then automatically build:

$ catapult watch

As I say, the source is incredibly simple. In the spirit of @fat's talk on documentation, I invite you to dive in.

Enjoying these posts? Subscribe for more