2016-03-21 22:53:02 +00:00
'use strict' ;
var _ = require ( 'lodash/fp' ) ;
2016-03-27 15:08:25 +00:00
var injectContentBetween = require ( '../util' ) . markdown . injectContentBetween ;
2016-03-21 22:53:02 +00:00
2016-03-22 18:53:10 +00:00
var badgeContent = '[![All Contributors](https://img.shields.io/badge/all_contributors-0-orange.svg?style=flat-square)](#contributors)' ;
2016-05-11 18:08:01 +00:00
var headerContent = 'Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):' ;
2016-03-22 18:53:10 +00:00
var listContent = '<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --><!-- ALL-CONTRIBUTORS-LIST:END -->' ;
2016-05-11 18:08:01 +00:00
var footerContent = 'This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!' ;
2016-03-21 22:53:02 +00:00
function addBadge ( lines ) {
2016-03-22 18:53:10 +00:00
return injectContentBetween ( lines , badgeContent , 1 , 1 ) ;
2016-03-21 22:53:02 +00:00
}
function splitAndRejoin ( fn ) {
return _ . flow (
_ . split ( '\n' ) ,
fn ,
_ . join ( '\n' )
) ;
}
var findContributorsSection = _ . findIndex ( function isContributorsSection ( str ) {
return str
. toLowerCase ( )
. indexOf ( '# contributors' ) === 1 ;
} ) ;
function addContributorsList ( lines ) {
var insertionLine = findContributorsSection ( lines ) ;
if ( insertionLine === - 1 ) {
return lines
. concat ( [
'## Contributors' ,
'' ,
2016-05-11 18:08:01 +00:00
headerContent ,
'' ,
listContent ,
'' ,
footerContent
2016-03-21 22:53:02 +00:00
] ) ;
}
2016-03-22 18:53:10 +00:00
return injectContentBetween ( lines , listContent , insertionLine + 2 , insertionLine + 2 ) ;
2016-03-21 22:53:02 +00:00
}
module . exports = {
addBadge : splitAndRejoin ( addBadge ) ,
addContributorsList : splitAndRejoin ( addContributorsList )
} ;