-
Notifications
You must be signed in to change notification settings - Fork 0
Solutions
lucentminds edited this page Jun 7, 2017
·
2 revisions
This example assumes that the main project has one or more sub-projects with build files located in a directory called modules.
Example project structure.
.
|-- modules/
| |-- module1/
| | `-- bobfile.js
| |-- module2/
| | `-- bobfile.js
| |-- module3/
| | `-- bobfile.js
|-- src/
`-- bobfile.js
// ./bobfile.js
var glob = require( 'promise-file-glob' );
var resolve = require( 'promise-resolve-path' );
var bob = require( 'builder-bob' );
var builder = module.exports = function( bob ){
// Create the "build" job for main.
var buildJobMain = bob.createJob( 'build' );
// Create the "build" job for modules.
var buildJobMods = bob.createJob( 'build-modules' );
// Use glob to quickly locate all of the sub-module bobfiles.
return glob( './modules/**/bobfile.js' )
// Resolve all of the paths to absolute paths.
.then( resolve )
// Add the "build" tasks from your modules to the main build.
.then(function( aBobfiles ){
buildJobMods.addDependencies( 'build', aBobfiles );
});
// Add module build task.
buildJob.addTask( 'build-modules', function(){
return buildJobMods.run();
});
// Add another task.
buildJob.addTask( 'concat', function(){ ...
// Create a "watch" job.
var watchJob = bob.createJob( 'watch' )...
// Always return bob. :)
return bob;
};// /export()
builder( bob ).getJob( 'build' ).run();Each module has a bobfile that looks like this...
// ./modules/module1/bobfile.js
var builder = module.exports = function( bob ){
// Create a new batch.
var batch = bob.createBatch( 'module1' );
// Create the "build" job.
var buildJob = batch.createJob( 'build', function(){
console.log( 'Put module build stuff here!' );
});
// Add another task to the build job.
buildJob.addTask( 'another-task', function(){
console.log( 'This is another task!' );
});
// Always return bob. :)
return bob;
};// /export()// ./bobfile.js
var bob = require( 'builder-bob' );
var builder = module.exports = function( bob ){
// Create the "build" job.
bob.createJob( 'build' )
.setTasks([
// Do this first.
{
task: 'empty',
do: function(){
// Create promises here.
}
},
// Do this second.
{
task: 'copy',
do: function(){
// Create promises here.
}
}
]);
// Always return bob. :)
return bob;
};// /export()
builder( bob ).getJob( 'build' ).run();Sometimes you don't want to have to wrap code in a promise.
// ./bobfile.js
var bob = require( '../builder-bob' );
var builder = module.exports = function( bob ){
// Create the "build" job.
var job = bob.createJob( 'build', function( result, next ){
console.log( 'No promises here!' );
next( 'foo' );
});
job.addTask( 'another-task', function( result, next ){
console.log( result ); // outputs: foo
next();
});
job.addTask( 'complete', function( result, next ){
console.log( result ); // outputs: undefined
console.log( 'complete!' );
next();
});
// Always return bob. :)
return bob;
};// /export()
builder( bob ).getJob( 'build' ).run();