From 905a63fd20a3e1aa4b6070676621357b25ce8088 Mon Sep 17 00:00:00 2001 From: oleg Date: Wed, 3 Dec 2014 00:09:05 +0300 Subject: [PATCH] exec -> run --- lib/command/spawn.js | 11 +++++++++-- lib/scm/index.js | 8 +++----- lib/scm/mercurial.js | 10 +++++----- test/scm.js | 2 +- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/command/spawn.js b/lib/command/spawn.js index 38c79fc..c671b57 100644 --- a/lib/command/spawn.js +++ b/lib/command/spawn.js @@ -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; diff --git a/lib/scm/index.js b/lib/scm/index.js index 5672f10..3b28630 100644 --- a/lib/scm/index.js +++ b/lib/scm/index.js @@ -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); }; diff --git a/lib/scm/mercurial.js b/lib/scm/mercurial.js index ca469b7..de67dd6 100644 --- a/lib/scm/mercurial.js +++ b/lib/scm/mercurial.js @@ -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); }; diff --git a/test/scm.js b/test/scm.js index d9bdbb0..d819d73 100644 --- a/test/scm.js +++ b/test/scm.js @@ -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) {