Skip to content

Commit

Permalink
feat: add footer with link to usage (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebolam committed Sep 28, 2022
1 parent 7a9150f commit b41e668
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 64 deletions.
1 change: 1 addition & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"repoType": "github",
"commit": false,
"contributorsPerLine": 6,
"linkToUsage": true,
"files": [
"README.md"
],
Expand Down
134 changes: 73 additions & 61 deletions README.md

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions assets/logo-small.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions src/generate/__tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,46 @@ These people contributed to the project:
<td align=\\"center\\">Jeroen Engels is awesome!</td>
</tr>
</tbody>
<tfoot>
</tfoot>
</table>
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
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:
<!-- ALL-CONTRIBUTORS-LIST:START -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tbody>
<tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Divjot Singh is awesome!</td>
<td align=\\"center\\">Jeroen Engels is awesome!</td>
</tr>
</tbody>
<tfoot>
<tr>
<td align=\\"center\\" size=\\"13px\\" colspan=\\"5\\">
<img src=\\"https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg\\">
<a href=\\"https://all-contributors.js.org/docs/en/bot/usage\\">Add your contributions</a>
</img>
</td>
</tr>
</tfoot>
</table>
<!-- markdownlint-restore -->
Expand Down Expand Up @@ -52,6 +92,52 @@ These people contributed to the project:
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
</tr>
</tbody>
<tfoot>
</tfoot>
</table>
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
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:
<!-- ALL-CONTRIBUTORS-LIST:START -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tbody>
<tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
</tr>
<tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
</tr>
</tbody>
<tfoot>
<tr>
<td align=\\"center\\" size=\\"13px\\" colspan=\\"5\\">
<img src=\\"https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg\\">
<a href=\\"https://all-contributors.js.org/docs/en/bot/usage\\">Add your contributions</a>
</img>
</td>
</tr>
</tfoot>
</table>
<!-- markdownlint-restore -->
Expand Down
26 changes: 26 additions & 0 deletions src/generate/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
18 changes: 15 additions & 3 deletions src/generate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,20 @@ function formatLine(contributors) {
)}</td>`
}

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 `<tr>\n <td align="center" size="13px" colspan="${options.contributorsPerLine}">\n <img src="${smallLogoURL}">\n <a href="${linkToBotAdd}">Add your contributions</a>\n </img>\n </td>\n </tr>`
}

function generateContributorsList(options, contributors) {
const contributorsPerLine = options.contributorsPerLine || 7
const tableFooter = formatFooter(options)

return _.flow(
_.sortBy(contributor => {
if (options.contributorsSortAlphabetically) {
Expand All @@ -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 </tr>\n <tr>\n '),
newContent => {
return `\n<table>\n <tbody>\n <tr>\n ${newContent}\n </tr>\n </tbody>\n</table>\n\n`
return `\n<table>\n <tbody>\n <tr>\n ${newContent}\n </tr>\n </tbody>\n <tfoot>\n ${tableFooter}\n </tfoot>\n</table>\n\n`
},
)(contributors)
}
Expand Down
7 changes: 7 additions & 0 deletions src/init/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -113,6 +119,7 @@ module.exports = function prompt() {
commitConvention: answers.commitConvention,
contributors: [],
contributorsPerLine: 7,
linkToUsage: answers.linkToUsage,
},
contributorFile: answers.contributorFile,
badgeFile: answers.badgeFile,
Expand Down

0 comments on commit b41e668

Please sign in to comment.