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") | - +
Jeroen Engels
Jeroen Engels

πŸ’» πŸ“– ⚠️
Kent C. Dodds
Kent C. Dodds

πŸ“– πŸ’»
JoΓ£o GuimarΓ£es
JoΓ£o GuimarΓ£es

πŸ’»
Ben Briggs
Ben Briggs

πŸ’»
Itai Steinherz
Itai Steinherz

πŸ“– πŸ’»
Alex Jover
Alex Jover

πŸ’» πŸ“–
Jerod Santo
Jerod Santo

πŸ’»
Kevin Jalbert
Kevin Jalbert

πŸ’»
tunnckoCore
tunnckoCore

πŸ”§
Mehdi Achour
Mehdi Achour

πŸ’»
Roy Revelt
Roy Revelt

πŸ›
Chris Vickery
Chris Vickery

πŸ’»
Bryce Reynolds
Bryce Reynolds

πŸ’»
James, please
James, please

πŸ€” πŸ’»
Spyros Ioakeimidis
Spyros Ioakeimidis

πŸ’»
Fernando Costa
Fernando Costa

πŸ’»
snipe
snipe

πŸ“–
Gant Laborde
Gant Laborde

πŸ’»
Md Zubair Ahmed
Md Zubair Ahmed

πŸ“– πŸ› πŸ’» ⚠️
Divjot Singh
Divjot Singh

πŸ“–
JoΓ£o Marques
JoΓ£o Marques

πŸ’» πŸ“– πŸ€”
Andrew Lisowski
Andrew Lisowski

πŸ’» πŸ“– ⚠️
Xianming Zhong
Xianming Zhong

πŸ“–
C.Y.Xu
C.Y.Xu

πŸ’»
Dura
Dura

πŸ“–
Jake Bolam
Jake Bolam

πŸš‡ πŸ’» πŸ“– ⚠️
Maximilian Berkmann
Maximilian Berkmann

πŸ’» ⚠️ πŸ“–
tbenning
tbenning

🎨
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
Kent C. Dodds](http://kentcdodds.com)
[πŸ‘€](#review-kentcdodds "Reviewed Pull Requests")' + 'Kent C. Dodds
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
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
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
Kent C. Dodds](http://kentcdodds.com)
[πŸ‘€](#review-kentcdodds "Reviewed Pull Requests")' + 'Kent C. Dodds
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?
Who | Needs | Pipes?](http://github.com/chrisinajar)
[πŸ“–](https://github.com/all-contributors/all-contributors-cli/commits?author=pipey "Documentation")' + 'Who | Needs | Pipes?
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
No Github Account
[🌍](#translation "Translation")' + 'No Github Account
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( + '<%= name %>', +) +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}${newContent}
\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) }