remote-origin-url
Advanced tools
Comparing version 0.2.1 to 0.3.0
59
index.js
@@ -1,7 +0,6 @@ | ||
/* | ||
* remote-origin-url | ||
* https://github.com/jonschlinkert/remote-origin-url | ||
/*! | ||
* remote-origin-url <https://github.com/jonschlinkert/remote-origin-url> | ||
* | ||
* Copyright (c) 2014 Jon Schlinkert | ||
* Licensed under the MIT license. | ||
* Copyright (c) 2014-2015, Jon Schlinkert. | ||
* Licensed under the MIT License. | ||
*/ | ||
@@ -11,23 +10,39 @@ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var ini = require('ini'); | ||
var chalk = require('chalk'); | ||
var findup = require('findup-sync'); | ||
var parse = require('parse-git-config'); | ||
var warn = chalk.yellow; | ||
/** | ||
* Expose `originUrl` | ||
*/ | ||
var origin = module.exports = function(dir) { | ||
var git = findup('.git/config', {cwd: dir || process.cwd()}); | ||
var str = fs.readFileSync(git, 'utf8'); | ||
return ini.parse(str); | ||
}; | ||
origin.url = function(dir) { | ||
module.exports = originUrl; | ||
function originUrl(cwd, cb) { | ||
if (typeof cwd === 'function') { | ||
cb = cwd; | ||
cwd = null; | ||
} | ||
parse(cwd, function (err, parsed) { | ||
if (err) { | ||
if (err.code === 'ENOENT') { | ||
cb(new Error('.git/config does not exist')); | ||
return; | ||
} | ||
cb(err); | ||
return; | ||
} | ||
var origin = parsed['remote "origin"']; | ||
cb(null, origin && origin.url); | ||
}); | ||
} | ||
originUrl.sync = function(cwd) { | ||
try { | ||
return origin(dir)['remote "origin"'].url; | ||
} catch(e) { | ||
e += '\n[remote-origin-url]: ' + warn('This probably means that a remote origin has not been defined for this repository yet.'); | ||
return new Error(e); | ||
var parsed = parse.sync(cwd); | ||
var origin = parsed['remote "origin"']; | ||
return origin && origin.url; | ||
} catch(err) { | ||
throw err; | ||
} | ||
}; | ||
}; |
{ | ||
"name": "remote-origin-url", | ||
"description": "Get the git remote origin URL from your local git repository. Remember! A remote origin must exist first!", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/jonschlinkert/remote-origin-url", | ||
@@ -17,7 +17,8 @@ "author": { | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/remote-origin-url/blob/master/LICENSE-MIT" | ||
} | ||
"license": { | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/remote-origin-url/blob/master/LICENSE" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
@@ -28,11 +29,11 @@ "main": "index.js", | ||
}, | ||
"devDependencies": { | ||
"chai": "~1.9.0", | ||
"mocha": "~1.17.1" | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"dependencies": { | ||
"chalk": "~0.4.0", | ||
"findup-sync": "~0.1.2", | ||
"ini": "~1.1.0" | ||
"parse-git-config": "^0.1.0" | ||
}, | ||
"devDependencies": { | ||
"should": "^5.0.1" | ||
}, | ||
"keywords": [ | ||
@@ -39,0 +40,0 @@ "git", |
@@ -1,15 +0,12 @@ | ||
# remote-origin-url [![NPM version](https://badge.fury.io/js/remote-origin-url.png)](http://badge.fury.io/js/remote-origin-url) | ||
# remote-origin-url [![NPM version](https://badge.fury.io/js/remote-origin-url.svg)](http://badge.fury.io/js/remote-origin-url) [![Build Status](https://travis-ci.org/jonschlinkert/remote-origin-url.svg)](https://travis-ci.org/jonschlinkert/remote-origin-url) | ||
> Get the git remote origin URL from your local git repository. Remember! A remote origin must exist first! | ||
## Installation | ||
## Install with [npm](npmjs.org) | ||
Install with [npm](https://npmjs.org/): | ||
```bash | ||
npm i remote-origin-url --save | ||
``` | ||
### Install with [bower](https://github.com/bower/bower) | ||
Install with [bower](https://github.com/bower/bower): | ||
```bash | ||
@@ -24,22 +21,56 @@ bower install remote-origin-url --save | ||
```js | ||
var origin = require('remote-origin-url'); | ||
console.log(origin.url()); | ||
// "https://github.com/jonschlinkert/remote-origin-url.git" | ||
var url = require('remote-origin-url'); | ||
url(function (err, res) { | ||
// res => "https://github.com/jonschlinkert/remote-origin-url.git" | ||
}) | ||
``` | ||
Specify the "base" directory, excluding `.git`. Example: | ||
Specify the `cwd` to use: | ||
```js | ||
url(__dirname, function (err, res) { | ||
// res => "https://github.com/jonschlinkert/remote-origin-url.git" | ||
}) | ||
``` | ||
origin.url(__dirname); | ||
### sync | ||
```js | ||
url.sync(); | ||
//=> "https://github.com/jonschlinkert/remote-origin-url.git" | ||
``` | ||
## Authors | ||
Specify the `cwd` to use: | ||
```js | ||
url.sync(__dirname); | ||
//=> "https://github.com/jonschlinkert/remote-origin-url.git" | ||
``` | ||
## Run tests | ||
Install dev dependencies: | ||
```bash | ||
npm i -d && npm test | ||
``` | ||
## Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/remote-origin-url/issues) | ||
## Author | ||
**Jon Schlinkert** | ||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
## License | ||
Copyright (c) 2014 [Jon Schlinkert](http://twitter.com/jonschlinkert), contributors. | ||
Released under the [MIT license](./LICENSE-MIT) | ||
Copyright (c) 2015 Jon Schlinkert | ||
Released under the MIT license | ||
*** | ||
_This file was generated by [verb](https://github.com/assemble/verb) on February 25, 2015._ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
1
1
76
0
4691
4
39
+ Addedparse-git-config@^0.1.0
+ Addedini@1.3.8(transitive)
+ Addedparse-git-config@0.1.0(transitive)
- Removedchalk@~0.4.0
- Removedfindup-sync@~0.1.2
- Removedini@~1.1.0
- Removedansi-styles@1.0.0(transitive)
- Removedchalk@0.4.0(transitive)
- Removedfindup-sync@0.1.3(transitive)
- Removedglob@3.2.11(transitive)
- Removedhas-color@0.1.7(transitive)
- Removedinherits@2.0.4(transitive)
- Removedini@1.1.0(transitive)
- Removedlodash@2.4.2(transitive)
- Removedlru-cache@2.7.3(transitive)
- Removedminimatch@0.3.0(transitive)
- Removedsigmund@1.0.1(transitive)
- Removedstrip-ansi@0.1.1(transitive)