mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-09 13:36:29 +00:00
This commit is contained in:
parent
47e408d5cd
commit
b7e5976e44
3 changed files with 29 additions and 35 deletions
|
@ -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"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
"contributors": []
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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:',
|
||||
'<!-- ALL-CONTRIBUTORS-LIST:START -->',
|
||||
'<!-- ALL-CONTRIBUTORS-LIST:END -->',
|
||||
'',
|
||||
'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();
|
||||
|
|
Loading…
Reference in a new issue