mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-09 13:36:29 +00:00
feat: add prettier-ignore to output (#74)
This commit is contained in:
parent
482a8ab956
commit
ba248a99d8
6 changed files with 92 additions and 77 deletions
34
src/generate/__tests__/__snapshots__/index.js.snap
Normal file
34
src/generate/__tests__/__snapshots__/index.js.snap
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of contributors 1`] = `
|
||||
"# project
|
||||
|
||||
Description
|
||||
|
||||
## Contributors
|
||||
These people contributed to the project:
|
||||
<!-- ALL-CONTRIBUTORS-LIST:START -->
|
||||
<!-- prettier-ignore -->
|
||||
| Kent C. Dodds is awesome! | Divjot Singh is awesome! | Jeroen Engels is awesome! |
|
||||
| :---: | :---: | :---: |
|
||||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||
|
||||
Thanks a lot everyone!"
|
||||
`;
|
||||
|
||||
exports[`split contributors into multiples lines when there are too many 1`] = `
|
||||
"# project
|
||||
|
||||
Description
|
||||
|
||||
## Contributors
|
||||
These people contributed to the project:
|
||||
<!-- ALL-CONTRIBUTORS-LIST:START -->
|
||||
<!-- prettier-ignore -->
|
||||
| Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! |
|
||||
| :---: | :---: | :---: | :---: | :---: |
|
||||
| Kent C. Dodds is awesome! | Kent C. Dodds is awesome! |
|
||||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||
|
||||
Thanks a lot everyone!"
|
||||
`;
|
|
@ -38,24 +38,9 @@ test('replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of c
|
|||
const {kentcdodds, bogas04} = contributors
|
||||
const {options, jfmengels, content} = fixtures()
|
||||
const contributorList = [kentcdodds, bogas04, jfmengels]
|
||||
const expected = [
|
||||
'# project',
|
||||
'',
|
||||
'Description',
|
||||
'',
|
||||
'## Contributors',
|
||||
'These people contributed to the project:',
|
||||
'<!-- ALL-CONTRIBUTORS-LIST:START -->',
|
||||
'| Kent C. Dodds is awesome! | Divjot Singh is awesome! | Jeroen Engels is awesome! |',
|
||||
'| :---: | :---: | :---: |',
|
||||
'<!-- ALL-CONTRIBUTORS-LIST:END -->',
|
||||
'',
|
||||
'Thanks a lot everyone!',
|
||||
].join('\n')
|
||||
|
||||
const result = generate(options, contributorList, content)
|
||||
|
||||
expect(result).toBe(expected)
|
||||
expect(result).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('split contributors into multiples lines when there are too many', () => {
|
||||
|
@ -70,25 +55,9 @@ test('split contributors into multiples lines when there are too many', () => {
|
|||
kentcdodds,
|
||||
kentcdodds,
|
||||
]
|
||||
const expected = [
|
||||
'# project',
|
||||
'',
|
||||
'Description',
|
||||
'',
|
||||
'## Contributors',
|
||||
'These people contributed to the project:',
|
||||
'<!-- ALL-CONTRIBUTORS-LIST:START -->',
|
||||
'| Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! |',
|
||||
'| :---: | :---: | :---: | :---: | :---: |',
|
||||
'| Kent C. Dodds is awesome! | Kent C. Dodds is awesome! |',
|
||||
'<!-- ALL-CONTRIBUTORS-LIST:END -->',
|
||||
'',
|
||||
'Thanks a lot everyone!',
|
||||
].join('\n')
|
||||
|
||||
const result = generate(options, contributorList, content)
|
||||
|
||||
expect(result).toBe(expected)
|
||||
expect(result).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('not inject anything if there is no tags to inject content in', () => {
|
||||
|
@ -150,6 +119,7 @@ test('inject nothing if there are no contributors', () => {
|
|||
'## Contributors',
|
||||
'These people contributed to the project:',
|
||||
'<!-- ALL-CONTRIBUTORS-LIST:START -->',
|
||||
'<!-- prettier-ignore -->',
|
||||
'<!-- ALL-CONTRIBUTORS-LIST:END -->',
|
||||
'',
|
||||
'Thanks a lot everyone!',
|
||||
|
|
|
@ -27,11 +27,12 @@ function injectListBetweenTags(newContent) {
|
|||
) {
|
||||
return previousContent
|
||||
}
|
||||
return (
|
||||
previousContent.slice(0, endOfOpeningTagIndex + closingTag.length) +
|
||||
newContent +
|
||||
previousContent.slice(startOfClosingTagIndex)
|
||||
)
|
||||
return [
|
||||
previousContent.slice(0, endOfOpeningTagIndex + closingTag.length),
|
||||
'\n<!-- prettier-ignore -->',
|
||||
newContent,
|
||||
previousContent.slice(startOfClosingTagIndex),
|
||||
].join('')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`create contributors section if content is empty 1`] = `
|
||||
"
|
||||
## Contributors
|
||||
|
||||
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
||||
<!-- prettier-ignore -->
|
||||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||
|
||||
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!"
|
||||
`;
|
||||
|
||||
exports[`create contributors section if it is absent 1`] = `
|
||||
"# project
|
||||
|
||||
Description
|
||||
## Contributors
|
||||
|
||||
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
||||
<!-- prettier-ignore -->
|
||||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||
|
||||
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!"
|
||||
`;
|
||||
|
||||
exports[`insert list under contributors section 1`] = `
|
||||
"# project
|
||||
|
||||
Description
|
||||
|
||||
## Contributors
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
||||
<!-- prettier-ignore -->
|
||||
<!-- ALL-CONTRIBUTORS-LIST:END -->"
|
||||
`;
|
|
@ -9,55 +9,21 @@ test('insert list under contributors section', () => {
|
|||
'## Contributors',
|
||||
'',
|
||||
].join('\n')
|
||||
const expected = [
|
||||
'# project',
|
||||
'',
|
||||
'Description',
|
||||
'',
|
||||
'## Contributors',
|
||||
'',
|
||||
'<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --><!-- ALL-CONTRIBUTORS-LIST:END -->',
|
||||
].join('\n')
|
||||
|
||||
const result = addContributorsList(content)
|
||||
|
||||
expect(result).toBe(expected)
|
||||
expect(result).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('create contributors section if it is absent', () => {
|
||||
const content = ['# project', '', 'Description'].join('\n')
|
||||
const expected = [
|
||||
'# project',
|
||||
'',
|
||||
'Description',
|
||||
'## Contributors',
|
||||
'',
|
||||
'Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):',
|
||||
'',
|
||||
'<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --><!-- ALL-CONTRIBUTORS-LIST:END -->',
|
||||
'',
|
||||
'This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!',
|
||||
].join('\n')
|
||||
|
||||
const result = addContributorsList(content)
|
||||
|
||||
expect(result).toBe(expected)
|
||||
expect(result).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('create contributors section if content is empty', () => {
|
||||
const content = ''
|
||||
const expected = [
|
||||
'',
|
||||
'## Contributors',
|
||||
'',
|
||||
'Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):',
|
||||
'',
|
||||
'<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --><!-- ALL-CONTRIBUTORS-LIST:END -->',
|
||||
'',
|
||||
'This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!',
|
||||
].join('\n')
|
||||
|
||||
const result = addContributorsList(content)
|
||||
|
||||
expect(result).toBe(expected)
|
||||
expect(result).toMatchSnapshot()
|
||||
})
|
||||
|
|
|
@ -5,8 +5,11 @@ const badgeContent =
|
|||
'[![All Contributors](https://img.shields.io/badge/all_contributors-0-orange.svg?style=flat-square)](#contributors)'
|
||||
const headerContent =
|
||||
'Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):'
|
||||
const listContent =
|
||||
'<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --><!-- ALL-CONTRIBUTORS-LIST:END -->'
|
||||
const listContent = [
|
||||
'<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->',
|
||||
'<!-- prettier-ignore -->',
|
||||
'<!-- ALL-CONTRIBUTORS-LIST:END -->',
|
||||
].join('\n')
|
||||
const footerContent =
|
||||
'This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!'
|
||||
|
||||
|
|
Loading…
Reference in a new issue