buildy

Jump to Table of Contents

Buildy is a build system for web/javascript/node.js projects. It acts like a sequence of 'piped' commands.

Installation

Install Buildy using npm:

$ npm install buildy -g

Or clone the GitHub repo to install the latest development version:

$ git clone git://github.com/mosen/buildy.git
$ cd buildy && npm install -g

Overview

Buildy exports several different objects which you can use with nodejs to create your own build script.

The main object you will be working with is the Queue object.

Queue

Each queue object is a description of a set of tasks that you want to perform as a part of your build process. Most of the time these tasks are executed one after another and they depend on the previous task.

Sample of constructing a queue of tasks sequentially

var Queue = require('buildy').Queue;

new Queue('release version')
    .task('files', ['./js/test1.js', './js/test2.js'])
    .task('concat')
    .task('jsminify')
    .task('write', { name: './build/test-min.js' })
    .run();

In this example, the Queue is constructed with the name 'release version'. The name of the queue is printed in any logs to give an indication of which queue is executing a task, and what the task result is.

Tasks are added to the queue using the task method. The first parameter is the name of a valid task (either one that ships with buildy, or a custom task that you added). The second parameter will be the task options, which varies depending on what kind of task you are adding to the Queue.

Queue in parallel

There may be tasks in your build process that can happen independently of other tasks, for example: you might be able to do a final run of your test suites, or produce documentation as a part of the script. You might just have several individual components that should be built at the same time.

There are two different ways to deal with this: forks and multiple queues

forks

When you specify a fork task in a queue, you are actually creating a set of new queue objects that inherit their state and configuration from the current Queue object. This allows you to diverge when you want to run several different build tasks acting on the same output.

Sample of the fork task
var Queue = require('buildy').Queue;

new Queue('fork example')
    .task('files', ['./js/test1.js', './js/test2.js'])
    .task('concat')
    .task('fork', {
        'first child queue' : function() {
            this.task('write', { name: './build/queue-a.js' }).run();
        },
        'second child queue' : function() {
            this.task('write', { name: './build/queue-b.js' }).run();
        }
    }).run();

In this example we take the concatenated contents of test1.js and test2.js, and write it to two different files (not very useful, i know). The point is that in the example, the writing of each file happens completely independently

creating multiple queues

If your build process has multiple different types of tasks to perform which are not in any way related, consider making multiple Queue's for this purpose

Sample of multiple queues
var Queue = require('buildy').Queue;

new Queue('scripts')
    .task('files', ['./js/test1.js', './js/test2.js'])
    .task('concat')
    .task('write', { name: './build/output.js' })
    .run();

new Queue('lint')
    .task('files', ['./js/test1.js'])
    .task('jslint')
    .run();

Here, each Queue is executed at the same time and doesn't rely on the output from any other task to complete