mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-01-25 16:16:16 +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;
|
||||
|
||||
function Command(params) {
|
||||
params = params || {};
|
||||
this.emitIn = params.emitIn;
|
||||
this.emitOut = params.emitOut;
|
||||
this.emitErr = params.emitErr;
|
||||
this.attachStderr = params.attachStderr;
|
||||
this.setParams(params);
|
||||
}
|
||||
|
||||
exports.Command = Command;
|
||||
|
||||
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');
|
||||
|
||||
function Command(params) {
|
||||
params = params || {};
|
||||
ParentCommand.call(this, params);
|
||||
this.cwd = params.cwd;
|
||||
ParentCommand.call(this, params || {});
|
||||
}
|
||||
|
||||
exports.Command = Command;
|
||||
|
||||
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`
|
||||
*/
|
||||
|
@ -1,22 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
var ParentCommand = require('../command/spawn').Command,
|
||||
inherits = require('util').inherits;
|
||||
var EventEmitter = require('events').EventEmitter,
|
||||
inherits = require('util').inherits,
|
||||
_ = require('underscore');
|
||||
|
||||
function Scm(params) {
|
||||
ParentCommand.call(this, params);
|
||||
this.repository = params.repository;
|
||||
if (!this.repository && !this.cwd) throw new Error(
|
||||
'`repository` or `cwd` must be set'
|
||||
);
|
||||
this.collectOut = true;
|
||||
this.emitIn = true;
|
||||
this.attachStderr = true;
|
||||
var self = this;
|
||||
|
||||
EventEmitter.call(self);
|
||||
|
||||
self.repository = params.repository;
|
||||
self.cwd = params.cwd;
|
||||
|
||||
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;
|
||||
|
||||
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`
|
||||
|
@ -1,6 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
var SpawnCommand = require('../command/spawn').Command;
|
||||
|
||||
exports.createScm = function(params) {
|
||||
var Constructor = require('./' + params.type).Scm;
|
||||
|
||||
params.command = params.command || new SpawnCommand();
|
||||
|
||||
return new Constructor(params);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user