UNPKG

sharegit

Version:
34 lines (29 loc) 758 B
/** * Findout origin url. * @function _detectOrigin * @private */ "use strict"; 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;