├── .gitignore ├── .npmignore ├── LICENSE.md ├── README.md ├── bin.js ├── index.js ├── package.json └── usage.txt /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | .DS_Store 4 | bundle.js 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | .DS_Store 4 | bundle.js 5 | test 6 | test.js 7 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | This software is released under the MIT license: 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so, 8 | subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # contributor-table 2 | 3 | ![](http://img.shields.io/badge/stability-stable-orange.svg?style=flat) 4 | ![](http://img.shields.io/npm/v/contributor-table.svg?style=flat) 5 | ![](http://img.shields.io/npm/dm/contributor-table.svg?style=flat) 6 | ![](http://img.shields.io/npm/l/contributor-table.svg?style=flat) 7 | 8 | Automatically inject a list of your git repository's contributors into your 9 | readme. 10 | 11 | ## Usage 12 | 13 | [![NPM](https://nodei.co/npm/contributor-table.png)](https://nodei.co/npm/contributor-table/) 14 | 15 | Usage: contributor-table {OPTIONS} 16 | 17 | Automatically inject a list of your git repository's 18 | contributors into your readme. 19 | 20 | Options: 21 | -d, --dirname The git project to check for contributors. Default: $(pwd) 22 | -r, --readme The readme file to process and update. Default: README.md 23 | -c, --check Ignore the email cache and prompt for new user details again. 24 | Useful for correcting mistakes. 25 | 26 | On encountering a new email address, you'll be prompted 27 | for that user's github/twitter accounts. This could be done 28 | semi-automatically but turns out it's just simpler this way. 29 | You'll only need to do this once per email on your system :) 30 | 31 | ## License 32 | 33 | MIT. See [LICENSE.md](http://github.com/hughsk/contributor-table/blob/master/LICENSE.md) for details. 34 | 35 | ## Contributors 36 | 37 | | Name | GitHub | Twitter | 38 | | ---------------- | ----------------------------------- | ------------------------------------------------- | 39 | | **Hugh Kennedy** | [hughsk](https://github.com/hughsk) | [@hughskennedy](https://twitter.com/hughskennedy) | 40 | -------------------------------------------------------------------------------- /bin.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const insertTable = require('mdast-contributors') 4 | const minimist = require('minimist') 5 | const mdast = require('mdast') 6 | const path = require('path') 7 | const grabDetails = require('./') 8 | const fs = require('fs') 9 | 10 | const argv = minimist(process.argv.slice(2), { 11 | boolean: ['c'], 12 | alias: { 13 | c: 'check', 14 | d: 'dirname', 15 | r: 'readme' 16 | }, 17 | default: { 18 | d: process.cwd() 19 | } 20 | }) 21 | 22 | argv.r = argv.readme = argv.r || ( 23 | path.resolve(argv.dirname, 'README.md') 24 | ) 25 | 26 | grabDetails(argv.dirname, { 27 | check: argv.check 28 | }, function (err, contributors) { 29 | if (err) throw err 30 | 31 | var readme = fs.readFileSync(argv.readme, 'utf8') 32 | 33 | readme = mdast.use(insertTable, { 34 | contributors: contributors 35 | }).process(readme) 36 | 37 | fs.writeFileSync(argv.readme, readme) 38 | }) 39 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const contributors = require('git-contributors').GitContributors 2 | const map = require('map-limit') 3 | const inquirer = require('inquirer') 4 | const userhome = require('userhome') 5 | const crypto = require('crypto') 6 | const mkdirp = require('mkdirp') 7 | const path = require('path') 8 | const fs = require('fs') 9 | 10 | module.exports = grabContributorDetails 11 | 12 | function grabContributorDetails (dirname, opts, done) { 13 | opts = opts || {} 14 | 15 | var memory = userhome('.contributor-table') 16 | var check = !!opts.check 17 | 18 | mkdirp.sync(memory) 19 | 20 | contributors.list({ 21 | cwd: path.resolve(dirname) 22 | }, function (err, users) { 23 | if (err) return done(err) 24 | 25 | map(users, 1, function (user, next) { 26 | var src = path.join(memory, crypto.createHash('md5') 27 | .update(user.email) 28 | .digest('hex') 29 | ) 30 | 31 | fs.readFile(src, function (err, login) { 32 | if (!check && !err && login) return next(null, JSON.parse(login)) 33 | 34 | inquirer.prompt([{ 35 | type: 'input', 36 | message: user.email + '\'s GitHub account?', 37 | name: 'github' 38 | }, { 39 | type: 'input', 40 | message: user.email + '\'s Twitter account?', 41 | name: 'twitter' 42 | }], function (results) { 43 | fs.writeFile(src, JSON.stringify(results), function(err) { 44 | return next(err, results) 45 | }) 46 | }) 47 | }) 48 | }, function (err, accounts) { 49 | if (err) return done(err) 50 | 51 | accounts = accounts.map(function (account, i) { 52 | account.email = users[i].email 53 | account.name = users[i].name 54 | return account 55 | }) 56 | 57 | done(null, accounts) 58 | }) 59 | }) 60 | } 61 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "contributor-table", 3 | "version": "1.0.0", 4 | "description": "Automatically inject a list of your git repository's contributors into your readme", 5 | "main": "index.js", 6 | "license": "MIT", 7 | "preferGlobal": true, 8 | "bin": { 9 | "contributor-table": "bin.js" 10 | }, 11 | "scripts": { 12 | "prepublish": "node bin" 13 | }, 14 | "author": { 15 | "name": "Hugh Kennedy", 16 | "email": "hughskennedy@gmail.com", 17 | "url": "http://hughsk.io/" 18 | }, 19 | "dependencies": { 20 | "git-contributors": "^0.2.3", 21 | "inquirer": "^0.8.5", 22 | "map-limit": "0.0.1", 23 | "mdast": "^0.22.0", 24 | "mdast-contributors": "^1.0.1", 25 | "minimist": "^1.1.1", 26 | "mkdirp": "^0.5.1", 27 | "userhome": "^1.0.0" 28 | }, 29 | "repository": { 30 | "type": "git", 31 | "url": "git://github.com/hughsk/contributor-table.git" 32 | }, 33 | "keywords": [ 34 | "readme", 35 | "github", 36 | "process", 37 | "contributors", 38 | "update", 39 | "lazy", 40 | "automatic" 41 | ], 42 | "homepage": "https://github.com/hughsk/contributor-table", 43 | "bugs": { 44 | "url": "https://github.com/hughsk/contributor-table/issues" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /usage.txt: -------------------------------------------------------------------------------- 1 | Usage: contributor-table {OPTIONS} 2 | 3 | Automatically inject a list of your git repository's 4 | contributors into your readme. 5 | 6 | Options: 7 | -d, --dirname The git project to check for contributors. Default: $(pwd) 8 | -r, --readme The readme file to process and update. Default: README.md 9 | -c, --check Ignore the email cache and prompt for new user details again. 10 | Useful for correcting mistakes. 11 | --------------------------------------------------------------------------------