Skip to content

Commit

Permalink
refactored some code for clarity purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
jshkurti committed Nov 14, 2014
1 parent ebc71c7 commit 10cf45c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 93 deletions.
35 changes: 9 additions & 26 deletions lib/identify.js
Expand Up @@ -5,33 +5,16 @@ module.exports = function(folder, cb) {
if (folder[folder.length - 1] !== '/')
folder += '/';

var isGit = function(cb) {
fs.exists(folder+'.git', function(exists) {
async.eachSeries(['git', 'hg', 'svn'],
function(type, callback) {
fs.exists(folder+'.'+type, function(exists) {
if (exists)
return cb('git');
return cb(null);
return callback(type);
else
return callback();
});
}

var isHg = function(cb) {
fs.exists(folder+'.hg', function(exists) {
if (exists)
return cb('hg');
return cb(null);
});
}

var isSvn = function(cb) {
fs.exists(folder+'.svn', function(exists) {
if (exists)
return cb('svn');
return cb(null);
});
}

async.series([isGit, isHg, isSvn], function(err, results) {
if (err !== null)
return cb(err, folder);
return cb('No versioning system found', folder);
},
function(final) {
return cb(final ? final : 'No versioning system found', folder);
});
}
93 changes: 27 additions & 66 deletions lib/vizion.js
@@ -1,61 +1,43 @@
var hg = require('./hg.js');
var git = require('./git.js');
var svn = require('./svn.js');
var ALL = {};
var vizion = {};

ALL.hg = require('./hg.js');
ALL.git = require('./git.js');
ALL.svn = require('./svn.js');
// Add more revision control tools here
var identify = require('./identify.js');

var vizion = {};

vizion.analyze = function(argv, cb) {
var _folder = (argv.folder != undefined) ? argv.folder : '.';

identify(_folder, function(type, folder) {
if (type === 'git')
return git.parse(folder, cb);
else if (type === 'hg')
return hg.parse(folder, cb);
else if (type === 'svn')
return svn.parse(folder, cb);
if (ALL[type])
return ALL[type].parse(folder, cb);
else
return cb({
msg : type,
path : folder
});
return cb('Error vizion::analyze() for given folder: '+folder);
});
}
};

vizion.isUpToDate = function(argv, cb) {
var _folder = (argv.folder != undefined) ? argv.folder : '.';

identify(_folder, function(type, folder) {
if (type === 'git')
return git.isUpdated(folder, cb);
// else if (type === 'hg')
// return hg.isUpdated(folder, cb);
else if (type === 'svn')
return svn.isUpdated(folder, cb);
if (ALL[type])
return ALL[type].isUpdated(folder, cb);
else
return cb({
msg : type,
path : folder
});
return cb('Error vizion::isUpToDate() for given folder: '+folder);
});
}
};

vizion.update = function(argv, cb) {
var _folder = (argv.folder != undefined) ? argv.folder : '.';

identify(_folder, function(type, folder) {
if (type === 'git')
return git.update(folder, cb);
// else if (type === 'hg')
// return hg.update(folder, cb);
else if (type === 'svn')
return svn.update(folder, cb);
if (ALL[type])
return ALL[type].update(folder, cb);
else
return cb({
msg : type,
path : folder
});
return cb('Error vizion::update() for given folder: '+folder);
});
}

Expand All @@ -67,53 +49,32 @@ vizion.revertTo = function(argv, cb) {
return cb({msg: 'Cannot revert to an invalid commit revision', path: _folder});

identify(_folder, function(type, folder) {
if (type === 'git')
return git.revert({folder: folder, revision: rev}, cb);
// else if (type === 'hg')
// return hg.revert({folder: folder, revision: rev}, cb);
// else if (type === 'svn')
// return svn.revert({folder: folder, revision: rev}, cb);
if (ALL[type])
return ALL[type].revert({folder: folder, revision: rev}, cb);
else
return cb({
msg : type,
path : folder
});
return cb('Error vizion::analyze() for given folder: '+folder);
});
}

vizion.prev = function(argv, cb) {
var _folder = (argv.folder != undefined) ? argv.folder : '.';

identify(_folder, function(type, folder) {
if (type === 'git')
return git.prev(folder, cb);
// else if (type === 'hg')
// return hg.update(folder, cb);
// else if (type === 'svn')
// return svn.update(folder, cb);
if (ALL[type])
return ALL[type].prev(folder, cb);
else
return cb({
msg : type,
path : folder
});
return cb('Error vizion::prev() for given folder: '+folder);
});
}

vizion.next = function(argv, cb) {
var _folder = (argv.folder != undefined) ? argv.folder : '.';

identify(_folder, function(type, folder) {
if (type === 'git')
return git.next(folder, cb);
// else if (type === 'hg')
// return hg.update(folder, cb);
// else if (type === 'svn')
// return svn.update(folder, cb);
if (ALL[type])
return ALL[type].next(folder, cb);
else
return cb({
msg : type,
path : folder
});
return cb('Error vizion::next() for given folder: '+folder);
});
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "vizion",
"version": "0.1.8",
"version": "0.1.9",
"engines": {
"node": ">=0.10"
},
Expand Down

0 comments on commit 10cf45c

Please sign in to comment.