mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-09 13:36:29 +00:00
feat(alpha-sort): Add a parameter contributorsSortAlphabetically (#249)
This parameter allows the user to sort the list of contributors in alphabetical order of their name.
This commit is contained in:
parent
8dd551a3d3
commit
b3d0995a65
3 changed files with 31 additions and 0 deletions
|
@ -35,6 +35,12 @@ const yargv = yargs
|
|||
.boolean('commit')
|
||||
.default('files', ['README.md'])
|
||||
.default('contributorsPerLine', 7)
|
||||
.option('contributorsSortAlphabetically', {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description:
|
||||
'Sort the list of contributors alphabetically in the generated list',
|
||||
})
|
||||
.default('contributors', [])
|
||||
.default('config', defaultRCFile)
|
||||
.config('config', configPath => {
|
||||
|
|
|
@ -60,6 +60,26 @@ test('split contributors into multiples lines when there are too many', () => {
|
|||
expect(result).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('sorts the list of contributors if contributorsSortAlphabetically=true', () => {
|
||||
const {kentcdodds, bogas04} = contributors
|
||||
const {options, jfmengels, content} = fixtures()
|
||||
|
||||
const resultPreSorted = generate(
|
||||
options,
|
||||
[bogas04, jfmengels, kentcdodds],
|
||||
content,
|
||||
)
|
||||
|
||||
options.contributorsSortAlphabetically = true
|
||||
const resultAutoSorted = generate(
|
||||
options,
|
||||
[jfmengels, kentcdodds, bogas04],
|
||||
content,
|
||||
)
|
||||
|
||||
expect(resultPreSorted).toEqual(resultAutoSorted)
|
||||
})
|
||||
|
||||
test('not inject anything if there is no tags to inject content in', () => {
|
||||
const {kentcdodds} = contributors
|
||||
const {options} = fixtures()
|
||||
|
|
|
@ -45,6 +45,11 @@ function formatLine(contributors) {
|
|||
|
||||
function generateContributorsList(options, contributors) {
|
||||
return _.flow(
|
||||
_.sortBy(function(contributor) {
|
||||
if (options.contributorsSortAlphabetically) {
|
||||
return contributor.name
|
||||
}
|
||||
}),
|
||||
_.map(function formatEveryContributor(contributor) {
|
||||
return formatContributor(options, contributor)
|
||||
}),
|
||||
|
|
Loading…
Reference in a new issue