Skip to content
Scott Johnson edited this page Jan 25, 2017 · 3 revisions

Hello, World!

// bobfile.js
var bob = require( 'builder-bob' );

var builder = module.exports = function( bob ){

    // Create the "build" job.
    var buildJob = bob.createJob( 'build', function(){
        console.log( 'Hello, World!' );
    });

    // Always return bob. :)
    return bob;

};// /export()

builder( bob ).getJob( 'build' ).run();

Now run bob.

node bobfile.js

The purpose of builder-bob is to remove the limitations of gulp, grunt, webpack, and other builder tools I've tried that didn't quite do all that I wanted them to do. This build tool is for those who know how to write code and are familiar with promises.

Things I liked about other solutions:

  • Gulp's syntax is just JavaScript. I'm a developer so this makes sense for me.
  • Gulp's use of globs for loading src files can also be used to load sub-project build files or "non-tracked" distribution build files.
  • Gruntfiles being an exported module allows it to be included in other scripts. I can use this idea for compiling sub-projects before compiling the main project.

Promises

I''ve been a big fan of promises. Ever since I was forced into asychronous programming, I have always been challenged with writing async code that is readable in a linear sequencial order. I think promises can be used as a primary component in a build tool to control flow and build order. I prefer to use q for promises rather than native JavaScript promises just because of familiarity.

The Overall idea

Here's some pseudo code to illustrate the concept.

// bobfile.js
module.exports = function( bob ){

    // Create the "build" job.
    var buildJob = bob.createJob( 'build' );

    // Asynchronously concatenate the css and js files together.
    buildJob.addTask( 'concat', function(){
        return Q.all([
            concat([
                'file1.css',
                'file2.css'
            ], 'file3.css' ),
            
            concat([
                'file1.js',
                'file2.js'
            ], 'file3.js' ),
        ]);
    });

    // Copy both compiled files to the public_html directory.
    buildJob.addTask( 'distribute', function(){
        return copy([
            'file3.css',
            'file3.js'
        ], '/var/public_html' )
    });

    // Create a "watch" job.
    var watchJob = bob.createJob( 'watch', function(){

        return watch( './src', function( cPathChanged ){

            // A file was changed.
            console.log( 'Changed:', cPathChanged );

            // Run the build job.
            buildJob.run();

        });
    });

    // Always return bob. :)
    return bob;

};// /export()

Once this is done we can run the build job.

// build.js
var bob = require( 'builder-bob' );
require( './bobfile.js' )( bob );

bob.getJob( 'build' ).run();

We can also run the watch job to build when files change by just changing the job name in the previous example.

bob.getJob( 'watch' ).run();

Possible CLI Use

I haven't built a cli yet, but with the preivous two bobfiles we could run the build job.

bob build

We could also run the watch job to build when files change.

bob watch

Clone this wiki locally