From b41e668fe40db14e1b8b9b1b74f5f661f82f2f38 Mon Sep 17 00:00:00 2001 From: Jake Bolam Date: Wed, 28 Sep 2022 12:54:52 -0400 Subject: [PATCH] feat: add footer with link to usage (#163) --- .all-contributorsrc | 1 + README.md | 134 ++++++++++-------- assets/logo-small.svg | 6 + .../__tests__/__snapshots__/index.js.snap | 86 +++++++++++ src/generate/__tests__/index.js | 26 ++++ src/generate/index.js | 18 ++- src/init/prompt.js | 7 + 7 files changed, 214 insertions(+), 64 deletions(-) create mode 100644 assets/logo-small.svg diff --git a/.all-contributorsrc b/.all-contributorsrc index b9055e21..0e57947e 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -5,6 +5,7 @@ "repoType": "github", "commit": false, "contributorsPerLine": 6, + "linkToUsage": true, "files": [ "README.md" ], diff --git a/README.md b/README.md index d08970f1..b2c2ad92 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,10 @@ -- [ all-contributors-cli ](#all-contributors-cli) + +- [ + all-contributors-cli +](#all-contributors-cli) - [The problem](#the-problem) - [This solution](#this-solution) - [Using the all-contributors-cli](#using-the-all-contributors-cli) @@ -81,90 +84,99 @@ Thanks goes to these wonderful people - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + + + + + +

Jeroen Engels

πŸ’» πŸ“– ⚠️

Kent C. Dodds

πŸ“– πŸ’»

JoΓ£o GuimarΓ£es

πŸ’»

Ben Briggs

πŸ’»

Itai Steinherz

πŸ“– πŸ’»

Alex Jover

πŸ’» πŸ“–
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

πŸ’»

Kevin Jalbert

πŸ’»

tunnckoCore

πŸ”§

Mehdi Achour

πŸ’»

Roy Revelt

πŸ›

Chris Vickery

πŸ’»
Jerod Santo
Jerod Santo

πŸ’»
Kevin Jalbert
Kevin Jalbert

πŸ’»
tunnckoCore
tunnckoCore

πŸ”§
Mehdi Achour
Mehdi Achour

πŸ’»
Roy Revelt
Roy Revelt

πŸ›
Chris Vickery
Chris Vickery

πŸ’»

Bryce Reynolds

πŸ’»

James, please

πŸ€” πŸ’»

Spyros Ioakeimidis

πŸ’»

Fernando Costa

πŸ’»

snipe

πŸ“–

Gant Laborde

πŸ’»
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

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

Divjot Singh

πŸ“–

JoΓ£o Marques

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

Andrew Lisowski

πŸ’» πŸ“– ⚠️

Xianming Zhong

πŸ“–

C.Y.Xu

πŸ’»
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

πŸ“–

Jake Bolam

πŸš‡ πŸ’» πŸ“– ⚠️ πŸ‘€ πŸ’¬

Maximilian Berkmann

πŸ’» ⚠️ πŸ“– πŸ”§ 🚧 πŸ‘€ πŸ’¬

tbenning

🎨

ehmicky

πŸ’»

James George

πŸ’»
Dura
Dura

πŸ“–
Jake Bolam
Jake Bolam

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

πŸ’» ⚠️ πŸ“– πŸ”§ 🚧 πŸ‘€ πŸ’¬
tbenning
tbenning

🎨
ehmicky
ehmicky

πŸ’»
James George
James George

πŸ’»

Nick Schonning

πŸ’»

Cezar Augusto

πŸ“–

Jeppe Reinhold

πŸ’»

Rachel M. Carmena

πŸ’»

simon3000

⚠️

SnOβ‚‚WMaN

πŸ’»
Nick Schonning
Nick Schonning

πŸ’»
Cezar Augusto
Cezar Augusto

πŸ“–
Jeppe Reinhold
Jeppe Reinhold

πŸ’»
Rachel M. Carmena
Rachel M. Carmena

πŸ’»
simon3000
simon3000

⚠️
SnOβ‚‚WMaN
SnOβ‚‚WMaN

πŸ’»

Fabrizio

πŸ› πŸ’»

kharaone

πŸ’»

Marcelo Alves

πŸ’» ⚠️

Anand Chowdhary

⚠️ πŸ› πŸ’»

Nicolas Goutay

πŸ’»

Tyler Krupicka

πŸ’» ⚠️
Fabrizio
Fabrizio

πŸ› πŸ’»
kharaone
kharaone

πŸ’»
Marcelo Alves
Marcelo Alves

πŸ’» ⚠️
Anand Chowdhary
Anand Chowdhary

⚠️ πŸ› πŸ’»
Nicolas Goutay
Nicolas Goutay

πŸ’»
Tyler Krupicka
Tyler Krupicka

πŸ’» ⚠️

Stefano Moia

πŸ’»

IlaΓ― Deutel

πŸ“¦

Justin Dalrymple

πŸ’»

Piotr StΔ™pniewski

πŸ› πŸ’» ⚠️

Gregor Martynus

πŸ‘€ πŸ’¬

Jeff Wen

πŸ‘€
Stefano Moia
Stefano Moia

πŸ’»
IlaΓ― Deutel
IlaΓ― Deutel

πŸ“¦
Justin Dalrymple
Justin Dalrymple

πŸ’»
Piotr StΔ™pniewski
Piotr StΔ™pniewski

πŸ› πŸ’» ⚠️
Gregor Martynus
Gregor Martynus

πŸ‘€ πŸ’¬
Jeff Wen
Jeff Wen

πŸ‘€

PaweΕ‚ Kowalski

πŸ’»

Markus LΓΆning

πŸ’»

David Anson

πŸ›

Jeroen Claassens

πŸ’»

Erek Speed

πŸ’»

Shai Reznik

πŸ› πŸ’» ⚠️
PaweΕ‚ Kowalski
PaweΕ‚ Kowalski

πŸ’»
Markus LΓΆning
Markus LΓΆning

πŸ’»
David Anson
David Anson

πŸ›
Jeroen Claassens
Jeroen Claassens

πŸ’»
Erek Speed
Erek Speed

πŸ’»
Shai Reznik
Shai Reznik

πŸ› πŸ’» ⚠️

Darek Kay

πŸ’» ⚠️

LaChapeliere

πŸ’»

SirWindfield

πŸ’»

G r e y

πŸ›‘οΈ

Lucas Cimon

πŸ“–

Josh Goldberg

πŸ›
Darek Kay
Darek Kay

πŸ’» ⚠️
LaChapeliere
LaChapeliere

πŸ’»
SirWindfield
SirWindfield

πŸ’»
G r e y
G r e y

πŸ›‘οΈ
Lucas Cimon
Lucas Cimon

πŸ“–
Josh Goldberg
Josh Goldberg

πŸ›

Angel Aviel Domaoan

πŸ’» πŸ‘€ πŸ“–

Rambaud Pierrick

πŸ’»
+ + Add your contributions + +
diff --git a/assets/logo-small.svg b/assets/logo-small.svg new file mode 100644 index 00000000..b8e512af --- /dev/null +++ b/assets/logo-small.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/generate/__tests__/__snapshots__/index.js.snap b/src/generate/__tests__/__snapshots__/index.js.snap index 15d4d74b..7278f002 100644 --- a/src/generate/__tests__/__snapshots__/index.js.snap +++ b/src/generate/__tests__/__snapshots__/index.js.snap @@ -18,6 +18,46 @@ These people contributed to the project: Jeroen Engels is awesome! + + + + + + + + + + +Thanks a lot everyone!" +`; + +exports[`replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of contributors with linkToUsage 1`] = ` +"# project + +Description + +## Contributors +These people contributed to the project: + + + + + + + + + + + + + + + +
Kent C. Dodds is awesome!Divjot Singh is awesome!Jeroen Engels is awesome!
+ + Add your contributions + +
@@ -52,6 +92,52 @@ These people contributed to the project: Kent C. Dodds is awesome! + + + + + + + + + + +Thanks a lot everyone!" +`; + +exports[`split contributors into multiples lines when there are too many with linkToUsage 1`] = ` +"# project + +Description + +## Contributors +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!
+ + Add your contributions + +
diff --git a/src/generate/__tests__/index.js b/src/generate/__tests__/index.js index ece35d58..cff3f7c1 100644 --- a/src/generate/__tests__/index.js +++ b/src/generate/__tests__/index.js @@ -43,6 +43,15 @@ test('replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of c expect(result).toMatchSnapshot() }) +test('replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of contributors with linkToUsage', () => { + const {kentcdodds, bogas04} = contributors + const {options, jfmengels, content} = fixtures() + const contributorList = [kentcdodds, bogas04, jfmengels] + const result = generate(Object.assign(options, { linkToUsage: true }), contributorList, content) + + expect(result).toMatchSnapshot() +}) + test('split contributors into multiples lines when there are too many', () => { const {kentcdodds} = contributors const {options, content} = fixtures() @@ -60,6 +69,23 @@ test('split contributors into multiples lines when there are too many', () => { expect(result).toMatchSnapshot() }) +test('split contributors into multiples lines when there are too many with linkToUsage', () => { + const {kentcdodds} = contributors + const {options, content} = fixtures() + const contributorList = [ + kentcdodds, + kentcdodds, + kentcdodds, + kentcdodds, + kentcdodds, + kentcdodds, + kentcdodds, + ] + const result = generate(Object.assign(options, { linkToUsage: true }), contributorList, content) + + expect(result).toMatchSnapshot() +}) + test('sorts the list of contributors if contributorsSortAlphabetically=true', () => { const {kentcdodds, bogas04} = contributors const {options, jfmengels, content} = fixtures() diff --git a/src/generate/index.js b/src/generate/index.js index 1f14e1e1..6dac4250 100644 --- a/src/generate/index.js +++ b/src/generate/index.js @@ -49,8 +49,20 @@ function formatLine(contributors) { )}` } +function formatFooter(options) { + if (!options.linkToUsage) { + return '' + } + const smallLogoURL = + 'https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg' + const linkToBotAdd = 'https://all-contributors.js.org/docs/en/bot/usage' + + return `\n \n \n Add your contributions\n \n \n ` +} + function generateContributorsList(options, contributors) { - const contributorsPerLine = options.contributorsPerLine || 7 + const tableFooter = formatFooter(options) + return _.flow( _.sortBy(contributor => { if (options.contributorsSortAlphabetically) { @@ -60,11 +72,11 @@ function generateContributorsList(options, contributors) { _.map(function formatEveryContributor(contributor) { return formatContributor(options, contributor) }), - _.chunk(contributorsPerLine), + _.chunk(options.contributorsPerLine), _.map(formatLine), _.join('\n \n \n '), newContent => { - return `\n\n \n \n ${newContent}\n \n \n
\n\n` + return `\n\n \n \n ${newContent}\n \n \n \n ${tableFooter}\n \n
\n\n` }, )(contributors) } diff --git a/src/init/prompt.js b/src/init/prompt.js index c6a402d8..c67fd8c3 100644 --- a/src/init/prompt.js +++ b/src/init/prompt.js @@ -86,6 +86,12 @@ const questions = [ choices: Object.values(conventions), default: 'angular', }, + { + type: 'confirm', + name: 'linkToUsage', + message: 'Do you want to add a footer with link to usage?', + default: true, + }, ] const uniqueFiles = _.flow(_.compact, _.uniq) @@ -113,6 +119,7 @@ module.exports = function prompt() { commitConvention: answers.commitConvention, contributors: [], contributorsPerLine: 7, + linkToUsage: answers.linkToUsage, }, contributorFile: answers.contributorFile, badgeFile: answers.badgeFile,