mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-02-10 19:29:15 +00:00
proxy shell input and output from command to executor
This commit is contained in:
parent
f120bde87d
commit
ce9dccba5d
@ -5,6 +5,7 @@ var EventEmitter = require('events').EventEmitter,
|
||||
|
||||
function Command(params) {
|
||||
params = params || {};
|
||||
this.emitIn = params.emitIn;
|
||||
this.emitOut = params.emitOut;
|
||||
}
|
||||
|
||||
|
@ -21,20 +21,29 @@ inherits(Command, ParentCommand);
|
||||
Command.prototype.run = function(params, callback) {
|
||||
var self = this,
|
||||
stdout = self.collectOut ? '' : null;
|
||||
|
||||
if (!params.cmd) return callback(new Error('`cmd` is not set'));
|
||||
if (!params.args) return callback(new Error('`args` is not set'));
|
||||
callback = utils.once(callback);
|
||||
params.options = params.options || {};
|
||||
params.options.cwd = params.options.cwd || this.cwd;
|
||||
|
||||
var cmd = spawn(params.cmd, params.args, params.options);
|
||||
|
||||
if (self.emitIn) {
|
||||
self.emit('stdin', params.cmd + ' ' + params.args.join(' '));
|
||||
}
|
||||
|
||||
cmd.stdout.on('data', function(data) {
|
||||
if (self.emitOut) self.emit('stdout', data);
|
||||
if (self.collectOut) stdout += data;
|
||||
});
|
||||
|
||||
cmd.stderr.on('data', function(data) {
|
||||
callback(new Error('Spawned command outputs to stderr: ' + data));
|
||||
cmd.kill();
|
||||
});
|
||||
|
||||
cmd.on('close', function(code) {
|
||||
var err = null;
|
||||
if (code !== 0) err = new Error(
|
||||
@ -42,5 +51,6 @@ Command.prototype.run = function(params, callback) {
|
||||
);
|
||||
callback(err, stdout);
|
||||
});
|
||||
|
||||
return cmd;
|
||||
};
|
||||
|
@ -55,11 +55,15 @@ Distributor.prototype._runNext = function(callback) {
|
||||
self.queue.splice(queueItemIndex, 1);
|
||||
|
||||
var stepCallback = this.slot();
|
||||
node.run(queueItem.project, build.params, function(err) {
|
||||
var executor = node.run(queueItem.project, build.params, function(err) {
|
||||
build.status = err ? 'error' : 'done';
|
||||
build.error = err;
|
||||
self._updateBuild(build, stepCallback);
|
||||
});
|
||||
|
||||
executor.on('data', function(data) {
|
||||
console.log('>>> executor`s data = ', data);
|
||||
});
|
||||
},
|
||||
callback
|
||||
);
|
||||
|
@ -2,7 +2,9 @@
|
||||
|
||||
var Steppy = require('twostep').Steppy,
|
||||
path = require('path'),
|
||||
_ = require('underscore');
|
||||
_ = require('underscore'),
|
||||
EventEmitter = require('events').EventEmitter,
|
||||
inherits = require('util').inherits;
|
||||
|
||||
function Executor(params) {
|
||||
this.project = params.project;
|
||||
@ -11,6 +13,8 @@ function Executor(params) {
|
||||
|
||||
exports.Executor = Executor;
|
||||
|
||||
inherits(Executor, EventEmitter);
|
||||
|
||||
Executor.prototype._getSources = function(params, callback) {
|
||||
};
|
||||
|
||||
|
@ -5,7 +5,8 @@ var Steppy = require('twostep').Steppy,
|
||||
ParentExecutor = require('./base').Executor,
|
||||
createScm = require('../scm').createScm,
|
||||
createCommand = require('../command').createCommand,
|
||||
fs = require('fs');
|
||||
fs = require('fs'),
|
||||
_ = require('underscore');
|
||||
|
||||
function Executor(params) {
|
||||
ParentExecutor.call(this, params);
|
||||
@ -61,7 +62,21 @@ Executor.prototype._runStep = function(params, callback) {
|
||||
}
|
||||
// set command cwd to executor cwd
|
||||
params.cwd = self.cwd;
|
||||
var command = createCommand(params);
|
||||
var command = createCommand(
|
||||
_({
|
||||
emitIn: true,
|
||||
emitOut: true
|
||||
}).extend(params)
|
||||
);
|
||||
|
||||
command.on('stdin', function(data) {
|
||||
self.emit('data', '> ' + String(data));
|
||||
});
|
||||
|
||||
command.on('stdout', function(data) {
|
||||
self.emit('data', String(data));
|
||||
});
|
||||
|
||||
command.run(params, this.slot())
|
||||
},
|
||||
callback
|
||||
|
@ -39,4 +39,6 @@ Node.prototype.run = function(project, params, callback) {
|
||||
delete self.executors[project.name];
|
||||
callback(err);
|
||||
});
|
||||
|
||||
return this.executors[project.name];
|
||||
};
|
||||
|
@ -6,6 +6,7 @@
|
||||
"rev": "default"
|
||||
},
|
||||
"steps": [
|
||||
{"type": "shell", "cmd": "echo 11"},
|
||||
{"type": "shell", "cmd": "echo 1 > 1.txt"},
|
||||
{"type": "shell", "cmd": "echo 2 > 2.txt"}
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user