Skip to content

Commit

Permalink
fix: add locale option and sort using locale (closes all-contributors…
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallhillCZ committed Jan 27, 2023
1 parent 96534ec commit 408a0f9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
24 changes: 20 additions & 4 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 => {
Expand Down
15 changes: 9 additions & 6 deletions src/generate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 408a0f9

Please sign in to comment.