Lineman.js

March 15th, 2014

I think it’s fair to say that JavaScript is no longer that “thing” we used to enhance our otherwise static web apps by adding some dynamic elements to it. Most users use a JavaScript enabled browser and users that lack JavaScript support are simply outnumbered. Without JavaScript you cannot use a large number of online services and this number is growing.

From time to time I’ve been playing around with JavaScript frameworks like Angular and Backbone. When you want to start an app with any of these frameworks - or in fact, any JavaScript app for that matter - you’ll quickly run into tools like Grunt and Bower. If you don’t know what they are, go ahead an see what they’re about. I’ll be here, waiting patiently for your return. On the other hand, you don’t need full knowledge of these tools, so you might as well read on.

The problem with starting an app like this is that it’s pretty harsh to set up. You may need configuration for compiling CoffeeScript and Less, a unit test library, something to run the tests, minimize JavaScript, run JSLint. The list may seem almost infinite.

Enter Lineman

Lineman is a thin wrapper around tools like Grunt and Test’em to take away the initial configuration burden from developers and let them focus on what they love most: building great apps.

Justin Searls, the creator of Lineman did a brilliant talk on what’s been wrong for years with building JavaScript apps. In this talk he gives an overview of some of the major problems you face with JavaScript development and how Lineman helps out. I’d recommend you to watch his talk.

The difference with Yeoman (a competing tool) is that Lineman is not based on code generation. Where Yeoman generates your initial project with a full Grunt configuration and example code (which you don’t need) and some other stuff, Lineman installs itself as your Grunt configuration. The benefit of this is that you can update your tools without breaking the configuration (or manually updating it).

With Lineman all you need to do to start building a new app is tell it to create one.

$ lineman new "app-name"

That’s it. It provides much like a walking skeleton for your application that you can run and test. Immediately you can enter your regular build cycle of changing code and have it automatically built and tested each time you save a file. If that’s not all, it’s blazingly fast. One of the goals the creators of Lineman set is for each incremental build and test run to take no more than a few hundred millis, independent of the size of the codebase. Now if that doesn’t stimulate TDD I don’t know what will.

To start the build cycle all you need to do is to fire up lineman run in one shell and lineman spec in another.

Both of these watch your sources so your app is build and tested whenever you save a change. You need to keep both running because lineman run compiles your sources and lineman spec watches the built files for running your specs. It took me a little help to find this out (much thanks to Justin for helping out).

Framework support

So what about framework support? Lineman creates a vanilla flavored app. This is the walking skeleton, but includes nothing like the framework support you can get from Yeoman.

Personally this is the way I prefer to start an app. Any libraries and frameworks I need I will include myself. Not only gives this full control to what vendor libs I actually use, it also gives me full control to when I want to use them and gives me the opportunity to defer their inclusion if I don’t need them (yet).

If you like to have some popular framework already included that’s okay, Lineman offers that too. All you need to do is to clone one of the Lineman template projects from Github and you’ll get a walking skeleton app with that framework. At the moment templates are provided for Backbone, Ember, and Angular, for building a library or a blog.

What’s next?

At this point I just want to start building things. The lineman website covers a lot of the configuration that’s possible.

Next to build and test configuration one of the first things I need in most apps is to be able to run end-to-end tests. I suspect Lineman can help me out with this too.

I hope I’ll keep enjoying Lineman as much as I do in the first few hours of using it.