mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-01-26 20:26:17 +00:00
scm uses command (but not command itself)
This commit is contained in:
parent
5a6a440d11
commit
a7840fc219
@ -4,23 +4,9 @@ var EventEmitter = require('events').EventEmitter,
|
|||||||
inherits = require('util').inherits;
|
inherits = require('util').inherits;
|
||||||
|
|
||||||
function Command(params) {
|
function Command(params) {
|
||||||
params = params || {};
|
this.setParams(params);
|
||||||
this.emitIn = params.emitIn;
|
|
||||||
this.emitOut = params.emitOut;
|
|
||||||
this.emitErr = params.emitErr;
|
|
||||||
this.attachStderr = params.attachStderr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Command = Command;
|
exports.Command = Command;
|
||||||
|
|
||||||
inherits(Command, EventEmitter);
|
inherits(Command, EventEmitter);
|
||||||
|
|
||||||
Command.prototype.enableEmitter = function() {
|
|
||||||
this.emitOut = true;
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
|
|
||||||
Command.prototype.disableEmitter = function() {
|
|
||||||
this.emitOut = false;
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
|
@ -6,15 +6,22 @@ var spawn = require('child_process').spawn,
|
|||||||
_ = require('underscore');
|
_ = require('underscore');
|
||||||
|
|
||||||
function Command(params) {
|
function Command(params) {
|
||||||
params = params || {};
|
ParentCommand.call(this, params || {});
|
||||||
ParentCommand.call(this, params);
|
|
||||||
this.cwd = params.cwd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Command = Command;
|
exports.Command = Command;
|
||||||
|
|
||||||
inherits(Command, ParentCommand);
|
inherits(Command, ParentCommand);
|
||||||
|
|
||||||
|
Command.prototype.setParams = function(params) {
|
||||||
|
if (params.cwd) this.cwd = params.cwd;
|
||||||
|
if (params.emitIn) this.emitIn = params.emitIn;
|
||||||
|
if (params.emitOut) this.emitOut = params.emitOut;
|
||||||
|
if (params.emitErr) this.emitErr = params.emitErr;
|
||||||
|
if (params.attachStderr) this.attachStderr = params.attachStderr;
|
||||||
|
if (params.collectOut) this.collectOut = params.collectOut;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes `params.cmd` with `params.args` and `params.options`
|
* Executes `params.cmd` with `params.args` and `params.options`
|
||||||
*/
|
*/
|
||||||
|
@ -1,22 +1,46 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var ParentCommand = require('../command/spawn').Command,
|
var EventEmitter = require('events').EventEmitter,
|
||||||
inherits = require('util').inherits;
|
inherits = require('util').inherits,
|
||||||
|
_ = require('underscore');
|
||||||
|
|
||||||
function Scm(params) {
|
function Scm(params) {
|
||||||
ParentCommand.call(this, params);
|
var self = this;
|
||||||
this.repository = params.repository;
|
|
||||||
if (!this.repository && !this.cwd) throw new Error(
|
EventEmitter.call(self);
|
||||||
'`repository` or `cwd` must be set'
|
|
||||||
);
|
self.repository = params.repository;
|
||||||
this.collectOut = true;
|
self.cwd = params.cwd;
|
||||||
this.emitIn = true;
|
|
||||||
this.attachStderr = true;
|
if (!self.repository && !self.cwd) {
|
||||||
|
throw new Error('`repository` or `cwd` must be set');
|
||||||
|
}
|
||||||
|
|
||||||
|
self.command = params.command;
|
||||||
|
|
||||||
|
self.command.setParams({
|
||||||
|
collectOut: true,
|
||||||
|
emitIn: true,
|
||||||
|
attachStderr: true
|
||||||
|
});
|
||||||
|
|
||||||
|
self.command.on('stdin', function(data) {
|
||||||
|
self.emit('stdin', data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Scm = Scm;
|
exports.Scm = Scm;
|
||||||
|
|
||||||
inherits(Scm, ParentCommand);
|
inherits(Scm, EventEmitter);
|
||||||
|
|
||||||
|
Scm.prototype.run = function(params, callback) {
|
||||||
|
if (this.cwd) {
|
||||||
|
params.options = params.options || {};
|
||||||
|
params.options.cwd = this.cwd;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.command.run(params, callback);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clone repository to the `dst` update to `rev` and set `this.cwd` to `dst`
|
* Clone repository to the `dst` update to `rev` and set `this.cwd` to `dst`
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var SpawnCommand = require('../command/spawn').Command;
|
||||||
|
|
||||||
exports.createScm = function(params) {
|
exports.createScm = function(params) {
|
||||||
var Constructor = require('./' + params.type).Scm;
|
var Constructor = require('./' + params.type).Scm;
|
||||||
|
|
||||||
|
params.command = params.command || new SpawnCommand();
|
||||||
|
|
||||||
return new Constructor(params);
|
return new Constructor(params);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user