all-contributors-cli
Advanced tools
Comparing version 2.0.0-beta4 to 2.0.0-beta5
@@ -8,2 +8,3 @@ #!/usr/bin/env node | ||
var init = require('./lib/init'); | ||
var generate = require('./lib/generate'); | ||
@@ -23,2 +24,4 @@ var markdown = require('./lib/markdown'); | ||
.usage('Usage: $0 add <username> <contribution>') | ||
.command('init', 'Prepare the project to be used with this tool') | ||
.usage('Usage: $0 init') | ||
.demand(2) | ||
@@ -65,3 +68,5 @@ .default('files', ['README.md']) | ||
if (command === 'generate') { | ||
if (command === 'init') { | ||
init(onError); | ||
} else if (command === 'generate') { | ||
startGeneration(argv, onError); | ||
@@ -68,0 +73,0 @@ } else if (command === 'add') { |
@@ -20,2 +20,6 @@ 'use strict'; | ||
function writeConfig(configPath, content, cb) { | ||
return fs.writeFile(configPath, formatCommaFirst(content), cb); | ||
} | ||
function writeContributors(configPath, contributors, cb) { | ||
@@ -29,3 +33,4 @@ var config = readConfig(configPath); | ||
readConfig: readConfig, | ||
writeConfig: writeConfig, | ||
writeContributors: writeContributors | ||
}; |
@@ -11,2 +11,4 @@ 'use strict'; | ||
var defaultImageSize = 100; | ||
function defaultTemplate(templateData) { | ||
@@ -21,4 +23,5 @@ var avatar = avatarTemplate(templateData); | ||
var paramJoiner = _.includes('?', avatarUrl) ? '&' : '?'; | ||
var imageSize = options.imageSize || defaultImageSize; | ||
return _.assign(contributor, { | ||
avatar_url: avatarUrl + paramJoiner + 's=' + options.imageSize | ||
avatar_url: avatarUrl + paramJoiner + 's=' + imageSize | ||
}); | ||
@@ -25,0 +28,0 @@ } |
@@ -10,3 +10,3 @@ import test from 'ava'; | ||
projectName: 'all-contributors-cli', | ||
imageSize: 100 | ||
imageSize: 150 | ||
}; | ||
@@ -20,3 +20,3 @@ return {options}; | ||
const expected = '[![Kent C. Dodds](https://avatars1.githubusercontent.com/u/1500684?s=100)<br /><sub>Kent C. Dodds</sub>](http://kentcdodds.com)<br />👀'; | ||
const expected = '[![Kent C. Dodds](https://avatars1.githubusercontent.com/u/1500684?s=150)<br /><sub>Kent C. Dodds</sub>](http://kentcdodds.com)<br />👀'; | ||
@@ -30,3 +30,3 @@ t.is(formatContributor(options, contributor), expected); | ||
const expected = '[![Kent C. Dodds](https://avatars1.githubusercontent.com/u/1500684?s=100)<br /><sub>Kent C. Dodds</sub>](http://kentcdodds.com)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=kentcdodds) 👀 ❓'; | ||
const expected = '[![Kent C. Dodds](https://avatars1.githubusercontent.com/u/1500684?s=150)<br /><sub>Kent C. Dodds</sub>](http://kentcdodds.com)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=kentcdodds) 👀 ❓'; | ||
@@ -59,7 +59,18 @@ t.is(formatContributor(options, contributor), expected); | ||
t.is(formatContributor(options, contributionWithoutQuestionMarkUrl), | ||
'Kent C. Dodds at www.some-url-without-question-mark.com?s=100' | ||
'Kent C. Dodds at www.some-url-without-question-mark.com?s=150' | ||
); | ||
t.is(formatContributor(options, contributionWithQuestionMarkUrl), | ||
'Kent C. Dodds at www.some-url-with-question-mark.com?v=3&s=100' | ||
'Kent C. Dodds at www.some-url-with-question-mark.com?v=3&s=150' | ||
); | ||
}); | ||
test('should default image size to 100', t => { | ||
const {options} = fixtures(); | ||
const contributor = contributors.kentcdodds; | ||
options.contributorTemplate = '<%= contributor.name %> at <%= contributor.avatar_url %>'; | ||
delete options.imageSize; | ||
t.is(formatContributor(options, contributor), | ||
'Kent C. Dodds at https://avatars1.githubusercontent.com/u/1500684?s=100' | ||
); | ||
}); |
@@ -6,22 +6,20 @@ 'use strict'; | ||
var formatContributor = require('./formatContributor'); | ||
var injectContentBetween = require('../markdown').injectContentBetween; | ||
function injectContentBetween(lines, content, startIndex, endIndex) { | ||
return [].concat( | ||
lines.slice(0, startIndex), | ||
content, | ||
lines.slice(endIndex) | ||
); | ||
function injectBetweenTags(tag, newContent) { | ||
return function (previousContent) { | ||
var tagToLookFor = '<!-- ALL-CONTRIBUTORS-' + tag + ':'; | ||
var closingTag = '-->'; | ||
var startOfOpeningTagIndex = previousContent.indexOf(tagToLookFor + 'START'); | ||
var endOfOpeningTagIndex = previousContent.indexOf(closingTag, startOfOpeningTagIndex); | ||
var startOfClosingTagIndex = previousContent.indexOf(tagToLookFor + 'END', endOfOpeningTagIndex); | ||
if (startOfOpeningTagIndex === -1 || endOfOpeningTagIndex === -1 || startOfClosingTagIndex === -1) { | ||
return previousContent; | ||
} | ||
return previousContent.slice(0, endOfOpeningTagIndex + closingTag.length) + | ||
newContent + | ||
previousContent.slice(startOfClosingTagIndex); | ||
}; | ||
} | ||
var injectBetweenTags = _.curry(function (tag, newContent, previousContent) { | ||
var lines = previousContent.split('\n'); | ||
var openingTagIndex = _.findIndex(_.startsWith('<!-- ALL-CONTRIBUTORS-' + tag + ':START '), lines); | ||
var closingTagIndex = _.findIndex(_.startsWith('<!-- ALL-CONTRIBUTORS-' + tag + ':END '), lines); | ||
if (openingTagIndex === -1 || closingTagIndex === -1) { | ||
return previousContent; | ||
} | ||
return injectContentBetween(lines, newContent, openingTagIndex + 1, closingTagIndex) | ||
.join('\n'); | ||
}); | ||
function formatLine(contributors) { | ||
@@ -55,5 +53,5 @@ return '| ' + contributors.join(' | ') + ' |'; | ||
return _.flow( | ||
injectBetweenTags('LIST', contributorsList), | ||
injectBetweenTags('LIST', '\n' + contributorsList + '\n'), | ||
injectBetweenTags('BADGE', badge) | ||
)(fileContent); | ||
}; |
@@ -30,5 +30,3 @@ import test from 'ava'; | ||
'These people contributed to the project:', | ||
'<!-- ALL-CONTRIBUTORS-LIST:START -->', | ||
'###Some content that will be replaced###', | ||
'<!-- ALL-CONTRIBUTORS-LIST:END -->', | ||
'<!-- ALL-CONTRIBUTORS-LIST:START -->FOO BAR BAZ<!-- ALL-CONTRIBUTORS-LIST:END -->', | ||
'', | ||
@@ -150,5 +148,3 @@ 'Thanks a lot guys!' | ||
'Badges', | ||
'<!-- ALL-CONTRIBUTORS-BADGE:START -->', | ||
'###Some content that will be replaced###', | ||
'<!-- ALL-CONTRIBUTORS-BADGE:END -->', | ||
'<!-- ALL-CONTRIBUTORS-BADGE:START --><!-- ALL-CONTRIBUTORS-BADGE:END -->', | ||
'', | ||
@@ -161,5 +157,3 @@ 'License: MIT' | ||
'Badges', | ||
'<!-- ALL-CONTRIBUTORS-BADGE:START -->', | ||
'[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors)', | ||
'<!-- ALL-CONTRIBUTORS-BADGE:END -->', | ||
'<!-- ALL-CONTRIBUTORS-BADGE:START -->[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors)<!-- ALL-CONTRIBUTORS-BADGE:END -->', | ||
'', | ||
@@ -166,0 +160,0 @@ 'License: MIT' |
@@ -13,5 +13,14 @@ 'use strict'; | ||
function injectContentBetween(lines, content, startIndex, endIndex) { | ||
return [].concat( | ||
lines.slice(0, startIndex), | ||
content, | ||
lines.slice(endIndex) | ||
); | ||
} | ||
module.exports = { | ||
read: read, | ||
write: write | ||
write: write, | ||
injectContentBetween: injectContentBetween | ||
}; |
{ | ||
"name": "all-contributors-cli", | ||
"version": "2.0.0-beta4", | ||
"version": "2.0.0-beta5", | ||
"description": "Tool to easily add recognition for new contributors", | ||
@@ -9,3 +9,3 @@ "bin": { | ||
"scripts": { | ||
"lint": "eslint cli.js \"lib/**/*.js\" && xo", | ||
"lint": "eslint cli.js \"lib/**/*.js\" && xo", | ||
"test": "npm run lint && npm run test-unit", | ||
@@ -30,10 +30,12 @@ "test-unit": "ava \"lib/**/*.test.js\"", | ||
"dependencies": { | ||
"async": "^2.0.0-rc.1", | ||
"inquirer": "^0.12.0", | ||
"lodash": "^4.6.1", | ||
"request": "^2.69.0", | ||
"yargs": "^4.2.0" | ||
"yargs": "^4.3.2" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.12.0", | ||
"eslint": "^2.3.0", | ||
"eslint-plugin-ava": "^1.1.1", | ||
"ava": "^0.13.0", | ||
"eslint": "^2.4.0", | ||
"eslint-plugin-ava": "^1.2.1", | ||
"xo": "^0.13.0" | ||
@@ -44,5 +46,10 @@ }, | ||
"rules": { | ||
"camelcase": [2, {"properties": "never"}] | ||
"camelcase": [ | ||
2, | ||
{ | ||
"properties": "never" | ||
} | ||
] | ||
} | ||
} | ||
} |
# all-contributors-cli | ||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --> | ||
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors) | ||
<!-- ALL-CONTRIBUTORS-BADGE:END --> | ||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors)<!-- ALL-CONTRIBUTORS-BADGE:END --> | ||
@@ -13,58 +11,26 @@ This is a tool to help automate adding contributor acknowledgements according to the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. | ||
```console | ||
npm install all-contributors-cli | ||
npm install all-contributors-cli -g | ||
``` | ||
## Configuration | ||
### Create a `.all-contributorsrc` file | ||
You must create a `.all-contributorsrc` JSON file. The data used to generate the contributors list will be stored in here, and you can configure how you want `all-contributors-cli` to generate the list. | ||
Then init the project using `init` and answering a few questions: | ||
```console | ||
all-contributors init | ||
``` | ||
Once initialized, you don't need to have `all-contributors-cli` instaled globally. You can instead save it as a devDependency of your project and add it to your scripts: | ||
```console | ||
npm install --save-dev all-contributors-cli | ||
``` | ||
```json | ||
{ | ||
"files": ["README.md"], | ||
"owner": "jfmengels", | ||
"types": { | ||
"cheerful": { | ||
"symbol": ":smiley:" | ||
} | ||
}, | ||
"contributors": [{ | ||
"login": "jfmengels", | ||
"...": "..." | ||
}] | ||
"scripts": { | ||
"add": "all-contributors add", | ||
"generate": "all-contributors generate" | ||
} | ||
} | ||
``` | ||
These are the keys you can specify: | ||
- `files`: Array of files to update. Default: `['README.md']` | ||
- `projectOwner`: Name of the user the project is hosted by. Example: `jfmengels/all-contributor-cli` --> `jfmengels`. Mandatory. | ||
- `projectName`: Name of the project. Example: `jfmengels/all-contributor-cli` --> `all-contributor-cli`. Mandatory. | ||
- `types`: Specify custom symbols or link templates for contribution types. Can override the documented types. | ||
- `imageSize`: Size (in px) of the user's avatar. Default: `100`. | ||
- `contributorsPerLine`: Maximum number of columns for the contributors table. Default: `7`. | ||
- `contributorTemplate`: Define your own template to generate the contributor list. | ||
- `badgeTemplate`: Define your own template to generate the badge. | ||
### Add contributors section | ||
If you don't already have a Contributors section in a Markdown file, create one. Then add the comment tags section below to it. Don't worry, they're visible only to those that read the raw file. The tags **must** be at the beginning of the line, and each on their separate line. | ||
```md | ||
## Contributors | ||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> | ||
<!-- ALL-CONTRIBUTORS-LIST:END --> | ||
and use them via `npm run`: | ||
```console | ||
npm run add -- jfmengels doc | ||
npm run generate | ||
``` | ||
If you wish to add a badge ( [![All Contributors](https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat-square)](#contributors) ) indicating the number of collaborators, add the following tags (again, at the beginning of the line and each on their separate line): | ||
```md | ||
some-badge | ||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --> | ||
<!-- ALL-CONTRIBUTORS-BADGE:END --> | ||
some-other-badge | ||
``` | ||
## Usage | ||
@@ -76,9 +42,9 @@ | ||
``` | ||
```console | ||
all-contributors generate | ||
``` | ||
### Add new contributor | ||
### Add/update contributors | ||
Use `add` to add new contributors to your project. They will be added to your configuration file. The contributors file will then be updated just as if you used the `generate` command. | ||
Use `add` to add new contributors to your project, or add new ways in which they contributed. They will be added to your configuration file. The contributors file will then be updated just as if you used the `generate` command. | ||
@@ -91,6 +57,3 @@ ```console | ||
``` | ||
Where: | ||
- `username` is the user's GitHub username | ||
- `contribution` is a `,`-separated list of ways to contribute, from the following list ([see the specs](https://github.com/kentcdodds/all-contributors#emoji-key)): | ||
Where `username` is the user's GitHub username, and `contribution` is a `,`-separated list of ways to contribute, from the following list ([see the specs](https://github.com/kentcdodds/all-contributors#emoji-key)): | ||
- code: 💻 | ||
@@ -112,3 +75,16 @@ - plugin: 🔌 | ||
## Configuration | ||
You can configure the project by updating the `.all-contributorsrc` JSON file. The data used to generate the contributors list will be stored in here, and you can configure how you want `all-contributors-cli` to generate the list. | ||
These are the keys you can specify: | ||
- `files`: Array of files to update. Default: `['README.md']` | ||
- `projectOwner`: Name of the user the project is hosted by. Example: `jfmengels/all-contributor-cli` --> `jfmengels`. Mandatory. | ||
- `projectName`: Name of the project. Example: `jfmengels/all-contributor-cli` --> `all-contributor-cli`. Mandatory. | ||
- `types`: Specify custom symbols or link templates for contribution types. Can override the documented types. | ||
- `imageSize`: Size (in px) of the user's avatar. Default: `100`. | ||
- `contributorsPerLine`: Maximum number of columns for the contributors table. Default: `7`. | ||
- `contributorTemplate`: Define your own template to generate the contributor list. | ||
- `badgeTemplate`: Define your own template to generate the badge. | ||
## Contributors | ||
@@ -115,0 +91,0 @@ |
Sorry, the diff of this file is not supported yet
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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
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
41129
27
1064
5
101
1
+ Addedasync@^2.0.0-rc.1
+ Addedinquirer@^0.12.0
+ Addedansi-escapes@1.4.0(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedasync@2.6.4(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedcli-cursor@1.0.2(transitive)
+ Addedcli-width@2.2.1(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedexit-hook@1.1.1(transitive)
+ Addedfigures@1.7.0(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedinquirer@0.12.0(transitive)
+ Addedmute-stream@0.0.5(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedonetime@1.1.0(transitive)
+ Addedreadline2@1.0.1(transitive)
+ Addedrestore-cursor@1.0.1(transitive)
+ Addedrun-async@0.1.0(transitive)
+ Addedrx-lite@3.1.2(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedthrough@2.3.8(transitive)
+ Addedwrappy@1.0.2(transitive)
Updatedyargs@^4.3.2