diff --git a/README.md b/README.md
index 27674212..c9bbd423 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,17 @@
+
+
+
+- [
+ all-contributors-cli
+ ](#all-contributors-cli)
+ - [The problem](#the-problem)
+ - [This solution](#this-solution)
+ - [Using the all-contributors-cli](#using-the-all-contributors-cli)
+ - [Contributors](#contributors)
+ - [LICENSE](#license)
+
+
+
> [There is now a GitHub Bot](https://github.com/all-contributors/all-contributors-bot) for automating the maintenance of your contributors table β¨
Say goodbye to command line tool dependencies and hello to the [@all-contributors bot π€](https://github.com/all-contributors/all-contributors-bot)
@@ -43,13 +57,7 @@ Thanks goes to these wonderful people
-| [
Jeroen Engels](https://github.com/jfmengels)
[π»](https://github.com/all-contributors/all-contributors-cli/commits?author=jfmengels "Code") [π](https://github.com/all-contributors/all-contributors-cli/commits?author=jfmengels "Documentation") [β οΈ](https://github.com/all-contributors/all-contributors-cli/commits?author=jfmengels "Tests") | [
Kent C. Dodds](http://kentcdodds.com/)
[π](https://github.com/all-contributors/all-contributors-cli/commits?author=kentcdodds "Documentation") [π»](https://github.com/all-contributors/all-contributors-cli/commits?author=kentcdodds "Code") | [
JoΓ£o GuimarΓ£es](https://github.com/jccguimaraes)
[π»](https://github.com/all-contributors/all-contributors-cli/commits?author=jccguimaraes "Code") | [
Ben Briggs](http://beneb.info)
[π»](https://github.com/all-contributors/all-contributors-cli/commits?author=ben-eb "Code") | [
Itai Steinherz](https://github.com/itaisteinherz)
[π](https://github.com/all-contributors/all-contributors-cli/commits?author=itaisteinherz "Documentation") [π»](https://github.com/all-contributors/all-contributors-cli/commits?author=itaisteinherz "Code") | [
Alex Jover](https://github.com/alexjoverm)
[π»](https://github.com/all-contributors/all-contributors-cli/commits?author=alexjoverm "Code") [π](https://github.com/all-contributors/all-contributors-cli/commits?author=alexjoverm "Documentation") |
-| :---: | :---: | :---: | :---: | :---: | :---: |
-| [
Jerod Santo](https://jerodsanto.net)
[π»](https://github.com/all-contributors/all-contributors-cli/commits?author=jerodsanto "Code") | [
Kevin Jalbert](https://github.com/kevinjalbert)
[π»](https://github.com/all-contributors/all-contributors-cli/commits?author=kevinjalbert "Code") | [
tunnckoCore](https://i.am.charlike.online)
[π§](#tool-charlike "Tools") | [
Mehdi Achour](https://machour.idk.tn/)
[π»](https://github.com/all-contributors/all-contributors-cli/commits?author=machour "Code") | [
Roy Revelt](https://codsen.com)
[π](https://github.com/all-contributors/all-contributors-cli/issues?q=author%3Arevelt "Bug reports") | [
Chris Vickery](https://github.com/chrisinajar)
[π»](https://github.com/all-contributors/all-contributors-cli/commits?author=chrisinajar "Code") |
-| [
Bryce Reynolds](https://github.com/brycereynolds)
[π»](https://github.com/all-contributors/all-contributors-cli/commits?author=brycereynolds "Code") | [
James, please](http://www.jmeas.com)
[π€](#ideas-jmeas "Ideas, Planning, & Feedback") [π»](https://github.com/all-contributors/all-contributors-cli/commits?author=jmeas "Code") | [
Spyros Ioakeimidis](http://www.spyros.io)
[π»](https://github.com/all-contributors/all-contributors-cli/commits?author=spirosikmd "Code") | [
Fernando Costa](https://github.com/fadc80)
[π»](https://github.com/all-contributors/all-contributors-cli/commits?author=fadc80 "Code") | [
snipe](https://snipe.net)
[π](https://github.com/all-contributors/all-contributors-cli/commits?author=snipe "Documentation") | [
Gant Laborde](http://gantlaborde.com/)
[π»](https://github.com/all-contributors/all-contributors-cli/commits?author=GantMan "Code") |
-| [
Md Zubair Ahmed](https://in.linkedin.com/in/mzubairahmed)
[π](https://github.com/all-contributors/all-contributors-cli/commits?author=M-ZubairAhmed "Documentation") [π](https://github.com/all-contributors/all-contributors-cli/issues?q=author%3AM-ZubairAhmed "Bug reports") [π»](https://github.com/all-contributors/all-contributors-cli/commits?author=M-ZubairAhmed "Code") [β οΈ](https://github.com/all-contributors/all-contributors-cli/commits?author=M-ZubairAhmed "Tests") | [
Divjot Singh](http://bogas04.github.io)
[π](https://github.com/all-contributors/all-contributors-cli/commits?author=bogas04 "Documentation") | [
JoΓ£o Marques](https://github.com/tigermarques)
[π»](https://github.com/all-contributors/all-contributors-cli/commits?author=tigermarques "Code") [π](https://github.com/all-contributors/all-contributors-cli/commits?author=tigermarques "Documentation") [π€](#ideas-tigermarques "Ideas, Planning, & Feedback") | [
Andrew Lisowski](http://hipstersmoothie.com)
[π»](https://github.com/all-contributors/all-contributors-cli/commits?author=hipstersmoothie "Code") [π](https://github.com/all-contributors/all-contributors-cli/commits?author=hipstersmoothie "Documentation") [β οΈ](https://github.com/all-contributors/all-contributors-cli/commits?author=hipstersmoothie "Tests") | [
Xianming Zhong](https://github.com/chinesedfan)
[π](https://github.com/all-contributors/all-contributors-cli/commits?author=chinesedfan "Documentation") | [
C.Y.Xu](https://github.com/xuchaoying)
[π»](https://github.com/all-contributors/all-contributors-cli/commits?author=xuchaoying "Code") |
-| [
Dura](https://github.com/chris-dura)
[π](https://github.com/all-contributors/all-contributors-cli/commits?author=chris-dura "Documentation") | [
Jake Bolam](https://jakebolam.com)
[π](#infra-jakebolam "Infrastructure (Hosting, Build-Tools, etc)") [π»](https://github.com/all-contributors/all-contributors-cli/commits?author=jakebolam "Code") [π](https://github.com/all-contributors/all-contributors-cli/commits?author=jakebolam "Documentation") [β οΈ](https://github.com/all-contributors/all-contributors-cli/commits?author=jakebolam "Tests") | [
Maximilian Berkmann](http://maxcubing.wordpress.com)
[π»](https://github.com/all-contributors/all-contributors-cli/commits?author=Berkmann18 "Code") [β οΈ](https://github.com/all-contributors/all-contributors-cli/commits?author=Berkmann18 "Tests") [π](https://github.com/all-contributors/all-contributors-cli/commits?author=Berkmann18 "Documentation") | [
tbenning](https://github.com/tbenning)
[π¨](#design-tbenning "Design") |
-
+
This project follows the
diff --git a/package.json b/package.json
index 2948e2a3..54453c46 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,9 @@
"lint": "kcd-scripts lint",
"test": "kcd-scripts test",
"validate": "kcd-scripts validate",
- "commit": "npx git-cz"
+ "commit": "git-cz",
+ "start": "./dist/cli.js",
+ "dev": "./src/cli.js"
},
"husky": {
"hooks": {
diff --git a/src/generate/__tests__/__snapshots__/index.js.snap b/src/generate/__tests__/__snapshots__/index.js.snap
index 69ab374a..3e4498e7 100644
--- a/src/generate/__tests__/__snapshots__/index.js.snap
+++ b/src/generate/__tests__/__snapshots__/index.js.snap
@@ -9,8 +9,7 @@ Description
These people contributed to the project:
-| Kent C. Dodds is awesome! | Divjot Singh is awesome! | Jeroen Engels is awesome! |
-| :---: | :---: | :---: |
+Kent C. Dodds is awesome! | Divjot Singh is awesome! | Jeroen Engels is awesome! |
Thanks a lot everyone!"
@@ -25,9 +24,7 @@ Description
These people contributed to the project:
-| Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! |
-| :---: | :---: | :---: | :---: | :---: |
-| Kent C. Dodds is awesome! | Kent C. Dodds is awesome! |
+Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! |
Kent C. Dodds is awesome! | Kent C. Dodds is awesome! |
Thanks a lot everyone!"
diff --git a/src/generate/__tests__/format-contribution-type.js b/src/generate/__tests__/format-contribution-type.js
index c873623f..1aa4e0f1 100644
--- a/src/generate/__tests__/format-contribution-type.js
+++ b/src/generate/__tests__/format-contribution-type.js
@@ -1,4 +1,4 @@
-import formatContributionType from '../format-contribution-type'
+import formatContributionType from '../format-contribution-type-html'
import contributors from './fixtures/contributors.json'
const fixtures = () => {
@@ -17,10 +17,10 @@ test('return corresponding symbol', () => {
const {options} = fixtures()
expect(formatContributionType(options, contributor, 'tool')).toBe(
- '[π§](#tool-kentcdodds "Tools")',
+ 'π§',
)
expect(formatContributionType(options, contributor, 'question')).toBe(
- '[π¬](#question-kentcdodds "Answering Questions")',
+ 'π¬',
)
})
@@ -31,13 +31,13 @@ test('return link to commits', () => {
'https://github.com/all-contributors/all-contributors-cli/commits?author=kentcdodds'
expect(formatContributionType(options, contributor, 'code')).toBe(
- `[π»](${expectedLink} "Code")`,
+ `π»`,
)
expect(formatContributionType(options, contributor, 'doc')).toBe(
- `[π](${expectedLink} "Documentation")`,
+ `π`,
)
expect(formatContributionType(options, contributor, 'test')).toBe(
- `[β οΈ](${expectedLink} "Tests")`,
+ `β οΈ`,
)
})
@@ -45,7 +45,7 @@ test('return link to issues', () => {
const contributor = contributors.kentcdodds
const {options} = fixtures()
const expected =
- '[π](https://github.com/all-contributors/all-contributors-cli/issues?q=author%3Akentcdodds "Bug reports")'
+ 'π'
expect(formatContributionType(options, contributor, 'bug')).toBe(expected)
})
@@ -59,7 +59,7 @@ test('make any symbol into a link if contribution is an object', () => {
}
expect(formatContributionType(options, contributor, contribution)).toBe(
- '[π§](www.foo.bar "Tools")',
+ 'π§',
)
})
@@ -72,7 +72,7 @@ test('override url for given types', () => {
}
expect(formatContributionType(options, contributor, contribution)).toBe(
- '[π»](www.foo.bar "Code")',
+ 'π»',
)
})
@@ -84,14 +84,14 @@ test('be able to add types to the symbol list', () => {
}
expect(formatContributionType(options, contributor, 'cheerful')).toBe(
- '[:smiley:](#cheerful-kentcdodds "")',
+ ':smiley:',
)
expect(
formatContributionType(options, contributor, {
type: 'cheerful',
url: 'www.foo.bar',
}),
- ).toBe('[:smiley:](www.foo.bar "")')
+ ).toBe(':smiley:')
})
test('be able to add types with template to the symbol list', () => {
@@ -105,7 +105,7 @@ test('be able to add types with template to the symbol list', () => {
}
expect(formatContributionType(options, contributor, 'web')).toBe(
- '[:web:](www.kentcdodds.com "")',
+ ':web:',
)
})
@@ -117,14 +117,14 @@ test('be able to override existing types', () => {
}
expect(formatContributionType(options, contributor, 'code')).toBe(
- '[:smiley:](#code-kentcdodds "")',
+ ':smiley:',
)
expect(
formatContributionType(options, contributor, {
type: 'code',
url: 'www.foo.bar',
}),
- ).toBe('[:smiley:](www.foo.bar "")')
+ ).toBe(':smiley:')
})
test('be able to override existing templates', () => {
@@ -138,14 +138,14 @@ test('be able to override existing templates', () => {
}
expect(formatContributionType(options, contributor, 'code')).toBe(
- '[:web:](www.kentcdodds.com "")',
+ ':web:',
)
expect(
formatContributionType(options, contributor, {
type: 'code',
url: 'www.foo.bar',
}),
- ).toBe('[:web:](www.foo.bar "")')
+ ).toBe(':web:')
})
test('throw a helpful error on unknown type', () => {
diff --git a/src/generate/__tests__/format-contributor.js b/src/generate/__tests__/format-contributor.js
index 652dc8a1..ba59a8c8 100644
--- a/src/generate/__tests__/format-contributor.js
+++ b/src/generate/__tests__/format-contributor.js
@@ -1,5 +1,5 @@
import _ from 'lodash/fp'
-import formatContributor from '../format-contributor'
+import formatContributor from '../format-contributor-html'
import contributors from './fixtures/contributors.json'
function fixtures() {
@@ -20,7 +20,7 @@ test('format a simple contributor', () => {
const {options} = fixtures()
const expected =
- '[
Kent C. Dodds](http://kentcdodds.com)
[π](#review-kentcdodds "Reviewed Pull Requests")'
+ '
Kent C. Dodds
π'
expect(formatContributor(options, contributor)).toBe(expected)
})
@@ -30,7 +30,7 @@ test('format contributor with complex contribution types', () => {
const {options} = fixtures()
const expected =
- '[
Kent C. Dodds](http://kentcdodds.com)
[π](https://github.com/all-contributors/all-contributors-cli/commits?author=kentcdodds "Documentation") [π](#review-kentcdodds "Reviewed Pull Requests") [π¬](#question-kentcdodds "Answering Questions")'
+ '
Kent C. Dodds
π π π¬'
expect(formatContributor(options, contributor)).toBe(expected)
})
@@ -53,7 +53,7 @@ test('default image size to 100', () => {
delete options.imageSize
const expected =
- '[
Kent C. Dodds](http://kentcdodds.com)
[π](#review-kentcdodds "Reviewed Pull Requests")'
+ '
Kent C. Dodds
π'
expect(formatContributor(options, contributor)).toBe(expected)
})
@@ -63,7 +63,7 @@ test('format contributor with pipes in their name', () => {
const {options} = fixtures()
const expected =
- '[
Who | Needs | Pipes?](http://github.com/chrisinajar)
[π](https://github.com/all-contributors/all-contributors-cli/commits?author=pipey "Documentation")'
+ '
Who | Needs | Pipes?
π'
expect(formatContributor(options, contributor)).toBe(expected)
})
@@ -73,7 +73,7 @@ test('format contributor with no github account', () => {
const {options} = fixtures()
const expected =
- '
No Github Account
[π](#translation "Translation")'
+ '
No Github Account
π'
expect(formatContributor(options, contributor)).toBe(expected)
})
diff --git a/src/generate/format-contribution-type-html.js b/src/generate/format-contribution-type-html.js
new file mode 100644
index 00000000..ebdde1ce
--- /dev/null
+++ b/src/generate/format-contribution-type-html.js
@@ -0,0 +1,52 @@
+const _ = require('lodash/fp')
+
+const util = require('../util')
+
+const linkTemplate = _.template(
+ '<%= symbol %>',
+)
+
+function getType(options, contribution) {
+ const types = util.contributionTypes(options)
+ return types[contribution.type || contribution]
+}
+
+module.exports = function formatContribution(
+ options,
+ contributor,
+ contribution,
+) {
+ const type = getType(options, contribution)
+
+ if (!type) {
+ throw new Error(
+ `Unknown contribution type ${contribution} for contributor ${contributor.login ||
+ contributor.name}`,
+ )
+ }
+
+ const templateData = {
+ symbol: type.symbol,
+ description: type.description,
+ contributor,
+ options,
+ }
+
+ let url = getUrl(contribution, contributor)
+
+ if (contribution.url) {
+ url = contribution.url
+ } else if (type.link) {
+ url = _.template(type.link)(templateData)
+ }
+
+ return linkTemplate(_.assign({url}, templateData))
+}
+
+function getUrl(contribution, contributor) {
+ if (contributor.login) {
+ return `#${contribution}-${contributor.login}`
+ } else {
+ return `#${contribution}`
+ }
+}
diff --git a/src/generate/format-contributor-html.js b/src/generate/format-contributor-html.js
new file mode 100644
index 00000000..e8054710
--- /dev/null
+++ b/src/generate/format-contributor-html.js
@@ -0,0 +1,59 @@
+const _ = require('lodash/fp')
+const formatContributionType = require('./format-contribution-type-html')
+
+const avatarTemplate = _.template(
+ '',
+)
+const avatarBlockTemplate = _.template(
+ '<%= avatar %>
<%= name %>',
+)
+const avatarBlockTemplateNoProfile = _.template(
+ '<%= avatar %>
<%= name %>',
+)
+const contributorTemplate = _.template(
+ '<%= avatarBlock %>
<%= contributions %>',
+)
+
+const defaultImageSize = 100
+
+function defaultTemplate(templateData) {
+ const name = escapeName(templateData.contributor.name)
+ const avatar = avatarTemplate(
+ _.assign(templateData, {
+ name,
+ }),
+ )
+ const avatarBlockTemplateData = _.assign(
+ {
+ name,
+ avatar,
+ },
+ templateData,
+ )
+ let avatarBlock = null
+
+ if (templateData.contributor.profile) {
+ avatarBlock = avatarBlockTemplate(avatarBlockTemplateData)
+ } else {
+ avatarBlock = avatarBlockTemplateNoProfile(avatarBlockTemplateData)
+ }
+
+ return contributorTemplate(_.assign({avatarBlock}, templateData))
+}
+
+function escapeName(name) {
+ return name.replace(new RegExp('\\|', 'g'), '|')
+}
+
+module.exports = function formatContributor(options, contributor) {
+ const formatter = _.partial(formatContributionType, [options, contributor])
+ const contributions = contributor.contributions.map(formatter).join(' ')
+ const templateData = {
+ contributions,
+ contributor,
+ options: _.assign({imageSize: defaultImageSize}, options),
+ }
+ const customTemplate =
+ options.contributorTemplate && _.template(options.contributorTemplate)
+ return (customTemplate || defaultTemplate)(templateData)
+}
diff --git a/src/generate/index.js b/src/generate/index.js
index c749889f..747ad4ef 100644
--- a/src/generate/index.js
+++ b/src/generate/index.js
@@ -1,7 +1,6 @@
const _ = require('lodash/fp')
-const injectContentBetween = require('../util').markdown.injectContentBetween
const formatBadge = require('./format-badge')
-const formatContributor = require('./format-contributor')
+const formatContributor = require('./format-contributor-html')
const badgeRegex = /\[!\[All Contributors\]\([a-zA-Z0-9\-./_:?=]+\)\]\(#\w+\)/
@@ -36,29 +35,22 @@ function injectListBetweenTags(newContent) {
}
}
-function formatLine(contributors) {
- return `| ${contributors.join(' | ')} |`
+function formatLineHtml(contributors) {
+ return `${contributors.join(' | ')} | `
}
-function createColumnLine(options, contributors) {
- const nbColumns = Math.min(options.contributorsPerLine, contributors.length)
- return `${_.repeat(nbColumns, '| :---: ')}|`
-}
-
-function generateContributorsList(options, contributors) {
+function generateContributorsListHtml(options, contributors) {
return _.flow(
_.map(function formatEveryContributor(contributor) {
return formatContributor(options, contributor)
}),
_.chunk(options.contributorsPerLine),
- _.map(formatLine),
- function insertColumns(lines) {
- const columnLine = createColumnLine(options, contributors)
- return injectContentBetween(lines, columnLine, 1, 1)
- },
- _.join('\n'),
+ _.map(formatLineHtml),
+ _.join(''),
newContent => {
- return `\n${newContent}\n`
+ const style =
+ ''
+ return `\n${style}\n`
},
)(contributors)
}
@@ -81,9 +73,10 @@ module.exports = function generate(options, contributors, fileContent) {
const contributorsList =
contributors.length === 0
? '\n'
- : generateContributorsList(options, contributors)
+ : generateContributorsListHtml(options, contributors)
const badge = formatBadge(options, contributors)
- return _.flow(injectListBetweenTags(contributorsList), replaceBadge(badge))(
- fileContent,
- )
+ return _.flow(
+ injectListBetweenTags(contributorsList),
+ replaceBadge(badge),
+ )(fileContent)
}