var builder = require('../builder'),
    async = require('async');

function runBuild(filename, config, options, callback) {
    config.out = filename + '.js';

    if (options.optimize) {
        config.optimize = options.optimize;
    }

    builder.writeConfig(config.output + '/' + filename + '.json', config, function(err, file) {
        builder.build(file, config, options.verbose, callback);
    });
}

function build(config, module, filter, options, callback) {
    var output = 'Building ' + module;

    if (filter) {
        output += ' with filter ' + filter;
    }

    console.log(output);

    config.generate(module, filter, function(err, config) {
        if (err) {
            throw err;
        }

        // The filename should be module[.filter]
        var filename = module.replace('/', '_');

        if (filter) {
            filename = filename + '.' + filter;
        }

        runBuild(filename, config, options, callback);
    });
}

function buildPlaceholder(config, module, filter, options, callback) {
    var output = 'Building ' + module + ' placeholder';

    if (filter) {
        output += ' with filter ' + filter;
    }

    console.log(output);

    config.generatePlaceholder(module, filter, function(err, config) {
        if (err) {
            throw err;
        }

        // The filename should be module[.filter].placeholder
        var filename = module.replace('/', '_');

        if (filter) {
            filename = filename + '.' + filter;
        }

        filename = filename + '.placeholder';

        runBuild(filename, config, options, callback);
    });
}

exports.all = function(config, options, callback) {
    async.eachLimit(config.getModules(), options.parallelBuilds, function(module, callback) {
        exports.module(config, module, null, options, callback);
    }, callback);
};

exports.module = function(config, module, filter, options, callback) {
    var buildFunc;

    if (options.placeholder === true) {
        buildFunc = buildPlaceholder;
    } else {
        buildFunc = build;
    }

    // If a module config has filters and the filter option is not set
    // we should build all
    if (!filter && config.getModuleFilters(module)) {
        async.each(config.getModuleFilters(module), function(filter, callback) {
            buildFunc(config, module, filter, options, callback);
        }, callback);
    } else {
        buildFunc(config, module, filter, options, callback);
    }
};

@@ -1660,24 +1660,124 @@
 callback) %7B%0A
+    if (typeof options.parallelBuilds === 'undefined') %7B%0A        options.parallelBuilds = 5;%0A    %7D%0A%0A
     async.ea

Set default value for parallelBuilds