From 408a0f93ddd5efd5e7367625facb9bf5228906b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kope=C4=8Dek?= Date: Fri, 27 Jan 2023 13:54:46 +0100 Subject: [PATCH] fix: add locale option and sort using locale (closes #349) --- src/cli.js | 24 ++++++++++++++++++++---- src/generate/index.js | 15 +++++++++------ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/cli.js b/src/cli.js index 1c52e96..dfc1c47 100755 --- a/src/cli.js +++ b/src/cli.js @@ -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 `) - .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 `, + ) + .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 => { diff --git a/src/generate/index.js b/src/generate/index.js index 11eaedb..4750cdb 100644 --- a/src/generate/index.js +++ b/src/generate/index.js @@ -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 \n \n '), newContent => { if (options.linkToUsage) {