generate step labels from cmd

This commit is contained in:
oleg 2015-05-07 22:03:57 +03:00
parent 94629bd27e
commit a6ff3b4f62
4 changed files with 18 additions and 5 deletions

View File

@ -67,8 +67,8 @@ Distributor.prototype._runNext = function(callback) {
}); });
}); });
executor.on('currentStep', function(stepName) { executor.on('currentStep', function(stepLabel) {
build.currentStep = stepName; build.currentStep = stepLabel;
self._updateBuild(build); self._updateBuild(build);
}); });

View File

@ -4,7 +4,8 @@ var Steppy = require('twostep').Steppy,
path = require('path'), path = require('path'),
_ = require('underscore'), _ = require('underscore'),
EventEmitter = require('events').EventEmitter, EventEmitter = require('events').EventEmitter,
inherits = require('util').inherits; inherits = require('util').inherits,
utils = require('../utils');
function Executor(params) { function Executor(params) {
this.project = params.project; this.project = params.project;
@ -33,7 +34,8 @@ Executor.prototype.run = function(params, callback) {
function() { function() {
var funcs = project.steps.map(function(step, index) { var funcs = project.steps.map(function(step, index) {
return function() { return function() {
self.emit('currentStep', step.name || ('step ' + index)); var stepLabel = step.name || utils.prune(step.cmd, 15);
self.emit('currentStep', stepLabel);
self._runStep(step, this.slot()); self._runStep(step, this.slot());
}; };
}); });

View File

@ -22,3 +22,14 @@ exports.once = function(func) {
isCalled = true; isCalled = true;
}; };
}; };
exports.prune = function(str, length) {
var result = '',
words = str.split(' ');
do {
result += words.shift() + ' ';
} while (words.length && result.length < length);
return result.replace(/ $/, result.length <= length ? '' : '...');
};

View File

@ -6,7 +6,7 @@
"rev": "default" "rev": "default"
}, },
"steps": [ "steps": [
{"type": "shell", "cmd": "echo \"hello, cur dir is `pwd`\""}, {"type": "shell", "cmd": "sleep 2 && echo \"hello, cur dir is `pwd`\""},
{"type": "shell", "name": "sleep", "cmd": "sleep 4"}, {"type": "shell", "name": "sleep", "cmd": "sleep 4"},
{"type": "shell", "cmd": "echo 1 > 1.txt"}, {"type": "shell", "cmd": "echo 1 > 1.txt"},
{"type": "shell", "cmd": "sleep 4"}, {"type": "shell", "cmd": "sleep 4"},