From b7e5976e445c087ac334b3c2b3721a1a1f90403e Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Wed, 11 May 2016 20:50:10 +0200 Subject: [PATCH] Inject some empty content when there are no contributors. Fixes #15 (#18) --- .all-contributorsrc | 34 ++-------------------------------- lib/generate/index.js | 9 ++++++--- lib/generate/index.test.js | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 35 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 13f8763..ed587a2 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -3,35 +3,5 @@ "projectName": "all-contributors-cli", "imageSize": 100, "commit": true, - "contributors": [ - { - "login": "jfmengels", - "name": "Jeroen Engels", - "avatar_url": "https://avatars.githubusercontent.com/u/3869412?v=3", - "profile": "https://github.com/jfmengels", - "contributions": [ - "code", - "doc", - "test" - ] - }, - { - "login": "kentcdodds", - "name": "Kent C. Dodds", - "avatar_url": "https://avatars.githubusercontent.com/u/1500684?v=3", - "profile": "http://kentcdodds.com/", - "contributions": [ - "doc" - ] - }, - { - "login": "jccguimaraes", - "name": "João Guimarães", - "avatar_url": "https://avatars.githubusercontent.com/u/14871650?v=3", - "profile": "https://github.com/jccguimaraes", - "contributions": [ - "code" - ] - } - ] -} \ No newline at end of file + "contributors": [] +} diff --git a/lib/generate/index.js b/lib/generate/index.js index 7eefa9a..c4324d4 100644 --- a/lib/generate/index.js +++ b/lib/generate/index.js @@ -18,7 +18,7 @@ function injectListBetweenTags(newContent) { return previousContent; } return previousContent.slice(0, endOfOpeningTagIndex + closingTag.length) + - '\n' + newContent + '\n' + + newContent + previousContent.slice(startOfClosingTagIndex); }; } @@ -43,7 +43,10 @@ function generateContributorsList(options, contributors) { var columnLine = createColumnLine(options, contributors); return injectContentBetween(lines, columnLine, 1, 1); }, - _.join('\n') + _.join('\n'), + function (newContent) { + return '\n' + newContent + '\n'; + } )(contributors); } @@ -60,7 +63,7 @@ function replaceBadge(newContent) { } module.exports = function generate(options, contributors, fileContent) { - var contributorsList = generateContributorsList(options, contributors); + var contributorsList = contributors.length === 0 ? '\n' : generateContributorsList(options, contributors); var badge = formatBadge(options, contributors); return _.flow( injectListBetweenTags(contributorsList), diff --git a/lib/generate/index.test.js b/lib/generate/index.test.js index 03dc057..d1361e5 100644 --- a/lib/generate/index.test.js +++ b/lib/generate/index.test.js @@ -136,6 +136,27 @@ test('should not inject anything if end tag is malformed', t => { t.is(result, content); }); +test('should inject nothing if there are no contributors', t => { + const {options, content} = fixtures(); + const contributorList = []; + const expected = [ + '# project', + '', + 'Description', + '', + '## Contributors', + 'These people contributed to the project:', + '', + '', + '', + 'Thanks a lot guys!' + ].join('\n'); + + const result = generate(options, contributorList, content); + + t.is(result, expected); +}); + test('should replace all-contributors badge if present', t => { const {kentcdodds} = contributors; const {options} = fixtures();