fix: add locale option and sort using locale (closes #349)

This commit is contained in:
Martin Kopeček 2023-01-27 13:54:46 +01:00
parent 96534ec59b
commit 408a0f93dd
2 changed files with 29 additions and 10 deletions

View file

@ -22,12 +22,22 @@ const yargv = yargs
.alias('v', 'version')
.version()
.recommendCommands()
.command('generate', `Generate the list of contributors\n\nUSAGE: all-contributors generate`)
.command('add', `Add a new contributor\n\nUSAGE: all-contributors add <username> <comma-separated contributions>`)
.command('init', `Prepare the project to be used with this tool\n\nUSAGE: all-contributors init`)
.command(
'generate',
`Generate the list of contributors\n\nUSAGE: all-contributors generate`,
)
.command(
'add',
`Add a new contributor\n\nUSAGE: all-contributors add <username> <comma-separated contributions>`,
)
.command(
'init',
`Prepare the project to be used with this tool\n\nUSAGE: all-contributors init`,
)
.command(
'check',
`Compare contributors from the repository with the ones credited in .all-contributorsrc'\n\nUSAGE: all-contributors check`)
`Compare contributors from the repository with the ones credited in .all-contributorsrc'\n\nUSAGE: all-contributors check`,
)
.boolean('commit')
.default('files', ['README.md'])
.default('contributorsPerLine', 7)
@ -37,6 +47,12 @@ const yargv = yargs
description:
'Sort the list of contributors alphabetically in the generated list',
})
.option('contributorsSortLocale', {
type: 'string',
default: undefined,
description:
'Locale to use for sorting the contributors alphabetically in the generated list',
})
.default('contributors', [])
.default('config', defaultRCFile)
.config('config', configPath => {

View file

@ -69,18 +69,21 @@ function generateContributorsList(options, contributors) {
let tableFooterContent = ''
return _.flow(
_.sortBy(contributor => {
c => {
if (options.contributorsSortAlphabetically) {
return contributor.name
c.sort((a, b) =>
a.name.localeCompare(b.name, options.contributorsSortLocale),
)
}
}),
return c
},
_.map(function formatEveryContributor(contributor) {
return formatContributor(options, contributor)
}),
_.chunk(options.contributorsPerLine),
_.map((currentLineContributors) => formatLine(
options, currentLineContributors
)),
_.map(currentLineContributors =>
formatLine(options, currentLineContributors),
),
_.join('\n </tr>\n <tr>\n '),
newContent => {
if (options.linkToUsage) {