Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
20 changes: 20 additions & 0 deletions src/generate/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions src/generate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}),
Expand Down