nci/lib/executor/base.js

51 lines
1.2 KiB
JavaScript
Raw Normal View History

'use strict';
var Steppy = require('twostep').Steppy,
path = require('path'),
_ = require('underscore'),
EventEmitter = require('events').EventEmitter,
2015-05-07 19:03:57 +00:00
inherits = require('util').inherits,
utils = require('../utils');
function Executor(params) {
this.project = params.project;
this.cwd = path.join(this.project.dir, 'workspace');
}
exports.Executor = Executor;
inherits(Executor, EventEmitter);
2015-05-20 20:49:53 +00:00
Executor.prototype.throttledEmit = _(function() {
this.emit.apply(this, arguments);
}).throttle(1500);
Executor.prototype._getSources = function(params, callback) {
};
Executor.prototype._runStep = function(params, callback) {
};
Executor.prototype.run = function(params, callback) {
var self = this,
project = _({}).extend(self.project, params);
Steppy(
function() {
2015-05-20 20:49:53 +00:00
self.throttledEmit('currentStep', 'get sources');
self._getSources(project.scm, this.slot());
},
2015-05-09 16:59:27 +00:00
function(err, scmData) {
self.emit('scmData', scmData);
2015-05-05 23:11:28 +00:00
var funcs = project.steps.map(function(step, index) {
return function() {
2015-05-20 20:49:53 +00:00
self.throttledEmit('currentStep', step.name);
self._runStep(step, this.slot());
};
});
funcs.push(this.slot());
Steppy.apply(this, funcs);
},
callback
);
};