exec -> run

This commit is contained in:
oleg 2014-12-03 00:09:05 +03:00
parent b1f91ebca4
commit 905a63fd20
4 changed files with 18 additions and 13 deletions

View File

@ -14,10 +14,17 @@ exports.SpawnCommand = Command;
inherits(Command, ParentCommand);
Command.prototype.exec = function(params, callback) {
/**
* Executes `params.cmd` with `params.args` and `params.options`
*/
Command.prototype.run = function(params, callback) {
var self = this,
stdout = '';
var cmd = spawn(params.cmd, params.args, {cwd: this.cwd});
if (!params.cmd) return callback(new Error('`cmd` is not set'));
if (!params.args) return callback(new Error('`args` is not set'));
params.options = params.options || {};
params.options.cwd = params.options.cwd || this.cwd;
var cmd = spawn(params.cmd, params.args, params.options);
cmd.stdout.on('data', function(data) {
if (self.isEmit) self.emit('stdout', data);
stdout += data;

View File

@ -1,12 +1,10 @@
'use strict';
var path = require('path');
var typesHash = {
'mercurial': require('./mercurial').MercurialScm
};
exports.createScm = function(config) {
var Constructor = typesHash[config.type];
return new Constructor(config);
exports.createScm = function(params) {
var Constructor = typesHash[params.type];
return new Constructor(params);
};

View File

@ -15,7 +15,7 @@ Scm.prototype.defaultRev = 'default';
Scm.prototype.clone = function(dst, rev, callback) {
var self = this;
this.exec({
this.run({
cmd: 'hg',
args: ['clone', '--rev', rev, this.repository, dst]
}, function(err) {
@ -25,17 +25,17 @@ Scm.prototype.clone = function(dst, rev, callback) {
};
Scm.prototype.pull = function(rev, callback) {
this.exec({cmd: 'hg', args: ['pull', '--rev', rev]}, callback);
this.run({cmd: 'hg', args: ['pull', '--rev', rev]}, callback);
};
Scm.prototype.getId = function(callback) {
this.exec({cmd: 'hg', args: ['id', '--id']}, function(err, stdout) {
this.run({cmd: 'hg', args: ['id', '--id']}, function(err, stdout) {
callback(err, !err && stdout.replace('\n', ''));
});
};
Scm.prototype.getChanges = function(rev1, rev2, callback) {
this.exec({cmd: 'hg', args: [
this.run({cmd: 'hg', args: [
'log', '--rev', rev2 + ':' + rev1,
'--template', '{node|short};;;{author};;;{date|date};;;{desc}\n'
]}, function(err, stdout) {
@ -52,5 +52,5 @@ Scm.prototype.getChanges = function(rev1, rev2, callback) {
};
Scm.prototype.update = function(rev, callback) {
this.exec({cmd: 'hg', args: ['up', rev]}, callback);
this.run({cmd: 'hg', args: ['up', rev]}, callback);
};

View File

@ -14,7 +14,7 @@ var expect = require('expect.js'),
repositoryPath = path.join(path.join(__dirname, 'repos'), repositoryName);
function rmdir(dir, callback) {
new SpawnCommand().exec({cmd: 'rm', args: ['-R', dir]}, callback);
new SpawnCommand().run({cmd: 'rm', args: ['-R', dir]}, callback);
}
it('remove test repository dir if it exists', function(done) {