sharegit
Version:
Share project to remote git repo.
34 lines (29 loc) • 758 B
JavaScript
/**
* Findout origin url.
* @function _detectOrigin
* @private
*/
;
const path = require('path');
/** @lends _detectOrigin */
function _detectOrigin() {
var pkg = require(path.resolve('package.json')),
repo = pkg.repository;
switch (typeof(repo)) {
case 'string':
if (/:/.test(repo)) {
return null;
} else {
return 'https://github.com/' + repo + (/\.git$/.test(repo) ? '' : '.git');
}
case 'object':
if (repo.type === 'git') {
return repo.url.split(/\+/).shift();
} else {
return null;
}
default:
return null;
}
}
module.exports = _detectOrigin;