diff --git a/runner.js b/runner.js index 90b2db8..ee0fdaa 100644 --- a/runner.js +++ b/runner.js @@ -1,3 +1,7 @@ +var ast = require('mkast') + , out = require('mkout') + , MAIN = 'main'; + /** * Get a task runner. * @@ -19,8 +23,13 @@ function runner(opts) { * @option {Object} task collection of tasks. */ function Runner(task) { + this.task = task; + this.tasks = task.tasks; this.scope = task.scope || {}; + + this.scope.ast = this.scope.ast || ast; + this.scope.out = this.scope.out || out; } /** @@ -164,9 +173,50 @@ function exec(id, cb) { return task; } +/** + * Execute a list of tasks to by string identifiers. + * + * @function each + * @member Runner + * + * @param {Array} [names] list of task names. + * @param {Function} cb callback function. + */ +function each(names, cb) { + if(names instanceof Function) { + cb = names; + names = null; + } + + if(!names) { + names = this.tasks.map(function(task) { + return task.id; + }) + } + + var scope = this; + names = names.slice(); + + function next(err) { + if(err) { + return cb(err); + } + var id = names.shift(); + if(!id) { + return cb(); + } + scope.exec(id, next); + } + + next(); +} + Runner.prototype.get = get; Runner.prototype.exec = exec; Runner.prototype.series = series; Runner.prototype.parallel = parallel; +Runner.prototype.each = each; + +Runner.prototype.MAIN = MAIN; module.exports = runner; diff --git a/test/fixtures/pipeline-task.js b/test/fixtures/pipeline-task.js new file mode 100644 index 0000000..b2cc43b --- /dev/null +++ b/test/fixtures/pipeline-task.js @@ -0,0 +1,12 @@ +var mk = require('../../index'); + +function readme(cb) { + doc('doc/readme.md') + //.pipe(this.pi()) + //.pipe(this.msg()) + //.pipe(this.ref()) + .pipe(mk.out('target/pipeline-task.js')) + .once('finish', cb); +} + +mk.task(readme); diff --git a/test/spec/run.js b/test/spec/run.js index b103c34..1a9370c 100644 --- a/test/spec/run.js +++ b/test/spec/run.js @@ -73,6 +73,8 @@ describe('mktask:', function() { function readme(cb) { called++; + expect(this.ast).to.be.an('object'); + expect(this.out).to.be.a('function'); cb(); }