master
jonschlinkert 10 years ago
parent d2382fee74
commit defd6cfea0

@ -7,11 +7,23 @@
## Usage ## Usage
```js ```js
var parseGitConfig = require('{%= name %}'); var gitConfig = require('{%= name %}');
``` ```
## API ### async
{%= apidocs("index.js") %}
```js
gitConfig(function (err, config) {
// do stuff with err/config
});
```
### sync
```js
gitConfig.sync();
```
## Run tests ## Run tests
@ -34,4 +46,4 @@ Pull requests and stars are always welcome. For bugs and feature requests, [plea
*** ***
{%= include("footer") %} {%= include("footer") %}

@ -10,29 +10,33 @@
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var ini = require('ini'); var ini = require('ini');
var lookup = require('look-up');
module.exports = config; /**
* Expose `config`
*/
module.exports = git;
function config(cwd, cb) { function git(cwd, cb) {
if (typeof cwd === 'function') { if (typeof cwd === 'function') {
cb = cwd; cwd = null; cb = cwd; cwd = null;
} }
var fp = path.join(cwd || process.cwd(), '.git/config'); if (typeof cb !== 'function') {
read(fp, function (err, buffer) { throw new TypeError('parse-git-config async expects a callback function.');
}
read(resolve(cwd), function (err, buffer) {
if (err) { if (err) {
cb(err); cb(err);
return; return;
} }
cb(null, ini.parse(buffer.toString()));
var data = ini.parse(buffer.toString());
return cb(null, data);
}); });
} }
config.sync = function configSync(cwd) { git.sync = function configSync(cwd) {
var fp = path.join(cwd || process.cwd(), '.git/config'); var fp = resolve(cwd);
if (!fs.existsSync(fp)) { if (!fs.existsSync(fp)) {
throw new Error('.git/config does not exist.'); throw new Error('.git/config does not exist.');
} }
@ -41,12 +45,17 @@ config.sync = function configSync(cwd) {
function read(fp, cb) { function read(fp, cb) {
try { try {
fs.readFile(fp, function (err, data) { fs.readFile(fp, function (err, config) {
if (err) return cb(err); if (err) {
return cb(err);
return cb(null, data); }
cb(null, config);
}); });
} catch (err) { } catch (err) {
cb(err); cb(err);
} }
} }
function resolve(cwd) {
return path.join(cwd || process.cwd(), '.git/config');
}

@ -1,6 +1,6 @@
{ {
"name": "parse-git-config", "name": "parse-git-config",
"description": "Parse .git/config into a JavaScript object.", "description": "Parse `.git/config` into a JavaScript object. sync or async.",
"version": "0.1.0", "version": "0.1.0",
"homepage": "https://github.com/jonschlinkert/parse-git-config", "homepage": "https://github.com/jonschlinkert/parse-git-config",
"author": { "author": {
@ -29,12 +29,14 @@
"test": "mocha" "test": "mocha"
}, },
"dependencies": { "dependencies": {
"ini": "^1.3.3", "ini": "^1.3.3"
"look-up": "^0.6.0"
}, },
"devDependencies": { "devDependencies": {
"mocha": "*", "mocha": "*",
"should": "*" "should": "*"
}, },
"keywords": [] "keywords": [
} "config",
"git"
]
}
Loading…
Cancel
Save