From 7812606e64f90b766b986df3602025477a61ca2b Mon Sep 17 00:00:00 2001 From: jonschlinkert Date: Tue, 24 Feb 2015 22:19:11 -0500 Subject: [PATCH] first commit --- .editorconfig | 17 +++++++++++++++++ .gitattributes | 1 + .gitignore | 12 ++++++++++++ .jshintrc | 18 +++++++++++++++++ .verb.md | 37 +++++++++++++++++++++++++++++++++++ LICENSE | 21 ++++++++++++++++++++ index.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 40 ++++++++++++++++++++++++++++++++++++++ test.js | 39 +++++++++++++++++++++++++++++++++++++ 9 files changed, 237 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .jshintrc create mode 100644 .verb.md create mode 100644 LICENSE create mode 100644 index.js create mode 100644 package.json create mode 100644 test.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..192641a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false + +[test/fixtures/*] +insert_final_newline = false +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a52bd18 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.* text eol=lf \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5c8a697 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +*.DS_store +*.sublime-* +_gh_pages +bower_components +node_modules +npm-debug.log +actual +test/actual +temp +tmp +TODO.md +vendor \ No newline at end of file diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..31eb603 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,18 @@ +{ + "asi": false, + "boss": true, + "curly": true, + "eqeqeq": true, + "eqnull": true, + "esnext": true, + "immed": true, + "latedef": true, + "laxcomma": false, + "newcap": true, + "noarg": true, + "node": true, + "sub": true, + "undef": "var", + "unused": true, + "mocha": true +} \ No newline at end of file diff --git a/.verb.md b/.verb.md new file mode 100644 index 0000000..f0960af --- /dev/null +++ b/.verb.md @@ -0,0 +1,37 @@ +# {%= name %} {%= badge("fury") %} + +> {%= description %} + +{%= include("install-npm", {save: true}) %} + +## Usage + +```js +var parseGitConfig = require('{%= name %}'); +``` + +## API +{%= apidocs("index.js") %} + + +## 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]({%= bugs.url %}) + +## Author +{%= include("author") %} + +## License +{%= copyright() %} +{%= license() %} + +*** + +{%= include("footer") %} \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..33754da --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Jon Schlinkert + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/index.js b/index.js new file mode 100644 index 0000000..e31ebcb --- /dev/null +++ b/index.js @@ -0,0 +1,52 @@ +/*! + * parse-git-config + * + * Copyright (c) 2015 Jon Schlinkert. + * Licensed under the MIT license. + */ + +'use strict'; + +var fs = require('fs'); +var path = require('path'); +var ini = require('ini'); +var lookup = require('look-up'); + +module.exports = config; + +function config(cwd, cb) { + if (typeof cwd === 'function') { + cb = cwd; cwd = null; + } + + var fp = path.join(cwd || process.cwd(), '.git/config'); + read(fp, function (err, buffer) { + if (err) { + cb(err); + return; + } + + var data = ini.parse(buffer.toString()); + return cb(null, data); + }); +} + +config.sync = function configSync(cwd) { + var fp = path.join(cwd || process.cwd(), '.git/config'); + if (!fs.existsSync(fp)) { + throw new Error('.git/config does not exist.'); + } + return ini.parse(fs.readFileSync(fp, 'utf8')); +}; + +function read(fp, cb) { + try { + fs.readFile(fp, function (err, data) { + if (err) return cb(err); + + return cb(null, data); + }); + } catch (err) { + cb(err); + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..d86b721 --- /dev/null +++ b/package.json @@ -0,0 +1,40 @@ +{ + "name": "parse-git-config", + "description": "Parse .git/config into a JavaScript object.", + "version": "0.1.0", + "homepage": "https://github.com/jonschlinkert/parse-git-config", + "author": { + "name": "Jon Schlinkert", + "url": "https://github.com/jonschlinkert" + }, + "repository": { + "type": "git", + "url": "git://github.com/jonschlinkert/parse-git-config.git" + }, + "bugs": { + "url": "https://github.com/jonschlinkert/parse-git-config/issues" + }, + "license": { + "type": "MIT", + "url": "https://github.com/jonschlinkert/parse-git-config/blob/master/LICENSE" + }, + "files": [ + "index.js" + ], + "main": "index.js", + "engines": { + "node": ">=0.10.0" + }, + "scripts": { + "test": "mocha" + }, + "dependencies": { + "ini": "^1.3.3", + "look-up": "^0.6.0" + }, + "devDependencies": { + "mocha": "*", + "should": "*" + }, + "keywords": [] +} diff --git a/test.js b/test.js new file mode 100644 index 0000000..72b0959 --- /dev/null +++ b/test.js @@ -0,0 +1,39 @@ +/*! + * parse-git-config + * + * Copyright (c) 2015 Jon Schlinkert. + * Licensed under the MIT license. + */ + +'use strict'; + +var should = require('should'); +var config = require('./'); + +describe('sync:', function () { + it('should return an object', function () { + config.sync().should.have.properties([]); + }); + + it('should throw an error when .git/config does not exist:', function () { + (function () { + config.sync('foo'); + }).should.throw('.git/config does not exist.'); + }); +}); + +describe('async:', function () { + it('should throw an error when .git/config does not exist:', function (cb) { + config(function (err, data) { + console.log(arguments) + }); + cb(); + }); + + it('should throw an error when .git/config does not exist:', function (cb) { + config('foo', function (err, data) { + console.log(arguments) + }); + cb(); + }); +});