Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Get author name from package.json even if author prop is an object #75

Merged
merged 3 commits into from
Jun 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@
"contributions": [
"code"
]
},
{
"login": "nekofar",
"name": "Milad Nekofar",
"avatar_url": "https://avatars3.githubusercontent.com/u/147401?v=4",
"profile": "http://milad.nekofar.com",
"contributions": [
"code",
"test",
"ideas"
]
}
],
"contributorsPerLine": 7,
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Feel free to check [issues page](https://github.com/kefranabg/readme-md-generato
<td align="center"><a href="https://github.com/ssoobratty"><img src="https://avatars3.githubusercontent.com/u/7631054?v=4" width="75px;" alt="Saffaanh Soobratty"/><br /><sub><b>Saffaanh Soobratty</b></sub></a><br /><a href="https://github.com/kefranabg/readme-md-generator/commits?author=ssoobratty" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/samit4me"><img src="https://avatars3.githubusercontent.com/u/3248531?v=4" width="75px;" alt="Samuel Sharpe"/><br /><sub><b>Samuel Sharpe</b></sub></a><br /><a href="https://github.com/kefranabg/readme-md-generator/commits?author=samit4me" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/apatrascu"><img src="https://avatars3.githubusercontent.com/u/1193770?v=4" width="75px;" alt="Alecsandru Patrascu"/><br /><sub><b>Alecsandru Patrascu</b></sub></a><br /><a href="https://github.com/kefranabg/readme-md-generator/commits?author=apatrascu" title="Code">💻</a></td>
<td align="center"><a href="http://milad.nekofar.com"><img src="https://avatars3.githubusercontent.com/u/147401?v=4" width="75px;" alt="Milad Nekofar"/><br /><sub><b>Milad Nekofar</b></sub></a><br /><a href="https://github.com/kefranabg/readme-md-generator/commits?author=nekofar" title="Code">💻</a> <a href="https://github.com/kefranabg/readme-md-generator/commits?author=nekofar" title="Tests">⚠️</a> <a href="#ideas-nekofar" title="Ideas, Planning, & Feedback">🤔</a></td>
</tr>
</table>

Expand Down
13 changes: 12 additions & 1 deletion src/project-infos.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ const getLicenseUrlFromGithubRepositoryUrl = repositoryUrl =>
const getReadmeUrlFromGithubRepositoryUrl = repositoryUrl =>
`${repositoryUrl}#readme`

/**
* Get project author name from package.json
*
* @param packageJson
* @returns {string} authorName
*/
const getAuthorName = packageJson => {
const pathToProp = has(packageJson, 'author.name') ? 'author.name' : 'author'
return get(packageJson, pathToProp, undefined)
}

/**
* Get project informations from git and package.json
*/
Expand All @@ -105,7 +116,7 @@ const getProjectInfos = async () => {
const name = getProjectName(packageJson)
const description = get(packageJson, 'description', undefined)
const engines = get(packageJson, 'engines', undefined)
const author = get(packageJson, 'author', undefined)
const author = getAuthorName(packageJson)
const version = get(packageJson, 'version', undefined)
const licenseName = get(packageJson, 'license', undefined)
const homepage = get(packageJson, 'homepage', undefined)
Expand Down
56 changes: 56 additions & 0 deletions src/project-infos.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,61 @@ describe('projectInfos', () => {
testCommand: undefined
})
})

it('should return correct infos when author is defined as an object', async () => {
const packgeJsonInfos = {
name: 'readme-md-generator',
version: '0.1.3',
description: 'CLI that generates beautiful README.md files.',
author: {
name: 'Franck Abgrall',
email: 'abgrallkefran@gmail.com',
url: ''
},
license: 'MIT',
homepage: 'https://github.com/kefranabg/readme-md-generator',
repository: {
type: 'git',
url: 'git+https://github.com/kefranabg/readme-md-generator.git'
},
bugs: {
url: 'https://github.com/kefranabg/readme-md-generator/issues'
},
engines: {
npm: '>=5.5.0',
node: '>=9.3.0'
}
}
utils.getPackageJson.mockReturnValueOnce(Promise.resolve(packgeJsonInfos))
childProcess.execSync.mockReturnValue(
'https://github.com/kefranabg/readme-md-generator.git'
)

const projectInfos = await getProjectInfos()

expect(projectInfos).toEqual({
name: 'readme-md-generator',
description: 'CLI that generates beautiful README.md files.',
version: '0.1.3',
author: 'Franck Abgrall',
repositoryUrl: 'https://github.com/kefranabg/readme-md-generator',
homepage: 'https://github.com/kefranabg/readme-md-generator',
contributingUrl:
'https://github.com/kefranabg/readme-md-generator/issues',
githubUsername: 'kefranabg',
engines: {
npm: '>=5.5.0',
node: '>=9.3.0'
},
licenseName: 'MIT',
licenseUrl:
'https://github.com/kefranabg/readme-md-generator/blob/master/LICENSE',
documentationUrl:
'https://github.com/kefranabg/readme-md-generator#readme',
isGithubRepos: true,
usage: undefined,
testCommand: undefined
})
})
})
})