Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tunnckoCore committed Feb 1, 2015
1 parent 58bee8b commit 4318ebe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 92 deletions.
82 changes: 28 additions & 54 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,25 @@
*/

'use strict';

var path = require('path');
var fmt = require('util').format;
// var del = require('rimraf-then'); // ????
var run = require('exec-cmd');
// var cwd = require('cwd'); // ????
var stringify = require('stringify-github-short-url');
var handleArguments = require('handle-arguments');

var errs = require('handle-errors')('gitclone', true);
var error = errs.error;
var type = errs.type;
var stringify = require('stringify-github-short-url');
var handleErrors = require('handle-errors')('gitclone');
var error = handleErrors.error;
var type = handleErrors.type;

// docs
module.exports = function gitclone() {
var argz = handleArguments(arguments);
var args = checkArguments(argz.args);
args = buildArguments(args);

return run(args.cmd, args.opts, argz.callback)
// .then(checkoutBranch(args));
return run(args.cmd, args.opts, argz.callback);
};

// workaround for branching
function checkoutBranch(args) {
return function _then(res) {
if (args.res.branch) {
var root = cwd();
process.chdir(cwd(args.dest));
var cmd = 'git checkout ' + args.res.branch;

return run(cmd, {stdio: [null, null, null]}).catch(function(err) {
console.log(root + '/' + args.dest);
del(root + '/' + args.dest)
return res;
})
}
return res;
}
}

function checkBranchExist(pattern) {

}

/**
* > Build and structure normalized arguments.
*
* @param {Array} `<args>`
* @return {Object}
* @api private
*/
function buildArguments(args) {
var dest = args.dest || args.opts.dest;
var data = args.res;
var git = 'git clone';
var url = args.opts.ssh ? 'git@github.com:' : 'https://github.com/';
var cmd = fmt('%s %s%s/%s.git', git, url, data.user, data.repo);
cmd = dest ? fmt('%s %s', cmd, dest) : cmd;

args.dest = dest ? dest : data.repo;
args.cmd = cmd;
args.cmd = data.branch ? fmt('%s -b %s', cmd, data.branch) : cmd;
// args.cmd = data.branch ? fmt('%s -b %s', cmd, data.branch) : cmd;
args.opts.stdio = args.opts.stdio ? args.opts.stdio : 'inherit';
return args;
}

/**
* > Create flexible arguments - check types and normalize incoming arguments.
*
Expand Down Expand Up @@ -107,6 +59,28 @@ function checkArguments(args) {
};
}

/**
* > Build and structure normalized arguments.
*
* @param {Array} `<args>`
* @return {Object}
* @api private
*/
function buildArguments(args) {
var dest = args.dest || args.opts.dest;
var data = args.res;
var git = 'git clone';
var url = args.opts.ssh ? 'git@github.com:' : 'https://github.com/';
var cmd = fmt('%s %s%s/%s.git', git, url, data.user, data.repo);
cmd = dest ? fmt('%s %s', cmd, dest) : cmd;

args.dest = dest ? dest : data.repo;
args.cmd = cmd;
args.cmd = data.branch ? fmt('%s -b %s', cmd, data.branch) : cmd;
args.opts.stdio = args.opts.stdio ? args.opts.stdio : 'inherit';
return args;
}

/**
* > Structure, order/reorder arguments when
* first argument (repo) is object.
Expand Down
38 changes: 0 additions & 38 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,3 @@
'use strict';

var gitclone = require('./index');


gitclone('tunnckoCore/async-exec-cmd', {ssh: true, dest: '../async-exec-cmd/'})
// gitclone('tunnckoCore/async-exec-cmd', function cb() {})
// gitclone('koajs/koa#0.14.0', 'releases/v0.14.0')
// gitclone('koajs/koa#0.15.0', 'releases/v0.15.0')
// gitclone('koajs/koa#0.16.0', 'releases/v0.16.0')
// gitclone('tunnckoCore/npmls', 'dest/to/path2', true/false)
// gitclone('tunnckoCore/npmls', 'dest/to/path3', {stdio: [null, null, null]})
// gitclone('tunnckoCore/npmls', {stdio: 'inherit'}, true)
// gitclone('tunnckoCore/npmls', {dest: 'dest/npmls', ssh: true}, false) // works, override ssh to false
// gitclone({
// user: 'koajs',
// repo: 'koa',
// branch: '0.12.0',
// dest: 'dest/koa',
// ssh: true,
// stdio: [null, null, null],
// })
// .catch(console.log)
// gitclone({
// user: 'tunnckoCore',
// repo: 'glob2fp',
// branch: 'yeah',
// options: {
// dest: 'dest/to/path5',
// ssh: true,
// stdio: 'inherit4'
// }
// })
// gitclone({
// user: 'tunnckoCore',
// repo: 'glob2fp',
// branch: 'feature',
// }, 'dest/to/path6', {
// ssh: false,
// stdio: 'falsefalsefalse'
// })

0 comments on commit 4318ebe

Please sign in to comment.