diff --git a/index.js b/index.js index 1ac0df6..d919c73 100644 --- a/index.js +++ b/index.js @@ -6,17 +6,15 @@ */ '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() { @@ -24,55 +22,9 @@ module.exports = function gitclone() { 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} `` - * @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. * @@ -107,6 +59,28 @@ function checkArguments(args) { }; } +/** + * > Build and structure normalized arguments. + * + * @param {Array} `` + * @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. diff --git a/test.js b/test.js index ccca53c..91624f1 100644 --- a/test.js +++ b/test.js @@ -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' -// })