Skip to content

Commit

Permalink
Merge 0cde7c0 into 4e8b5c7
Browse files Browse the repository at this point in the history
  • Loading branch information
nexdrew committed Nov 16, 2015
2 parents 4e8b5c7 + 0cde7c0 commit c73d829
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"tmp": "0.0.28"
},
"dependencies": {
"es6-promise": "^3.0.2"
"all-stars": "^1.0.0",
"es6-promise": "^3.0.2",
"object-assign": "^4.0.1"
}
}
23 changes: 19 additions & 4 deletions util/package.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
'use strict';

var allStars = require( 'all-stars' );
var objectAssign = require( 'object-assign' );

/**
* Check all-stars db for given person and assign to person if found.
*
* @param {Object} person object representing author or maintainer
*
* @return {Object} same object given, possibly modified or augmented
*/
function getAllStar( person ) {
// override properties from all-stars if available
return objectAssign( person, allStars( person ) );
}

/**
* Parse npm string shorthand into object representation
*
Expand All @@ -10,11 +25,11 @@
function getPersonObject( personString ) {
var regex = personString.match( /^(.*?)\s?(<(.*)>)?\s?(\((.*)\))?\s?$/ );

return {
return getAllStar( {
name : regex[ 1 ],
email : regex[ 3 ],
url : regex[ 5 ]
};
} );
}


Expand All @@ -33,7 +48,7 @@ function getAuthor( packageJson ) {
}

return packageJson.author ?
packageJson.author :
getAllStar( packageJson.author ) :
false;
}

Expand All @@ -54,7 +69,7 @@ function getMaintainers( packageJson ) {
return getPersonObject( maintainer );
}

return maintainer;
return getAllStar( maintainer );
} );
}

Expand Down
35 changes: 35 additions & 0 deletions util/package.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import test from 'ava';
import { authors, index } from 'all-stars';
import packageUtil from './package';

test( 'getAuthor - author is a string', t => {
Expand Down Expand Up @@ -77,6 +78,40 @@ test( 'getAuthor - author is not defined', t => {
t.end();
} );

test( 'getAuthor - author in all-stars has additional properties', t => {
let packageJson = {
author : {
name : 'Archimedes of Syracuse',
email : 'archimedes@syracuse.io',
url : 'https://en.wikipedia.org/wiki/Archimedes'
}
};

// add our fake author to all-stars for mocking purposes
let fakeAuthorId = 'PiDude314159265359';

authors[ fakeAuthorId ] = {
npmUsers : [ fakeAuthorId ],
names : [ packageJson.author.name ],
emails : [ packageJson.author.email ],
githubUsers : [ fakeAuthorId ],
twitters : [ fakeAuthorId ]
};

index[ packageJson.author.name ] = fakeAuthorId;
index[ packageJson.author.email ] = fakeAuthorId;

// test
let author = packageUtil.getAuthor( packageJson );

t.is( author.name, packageJson.author.name );
t.is( author.email, packageJson.author.email );
t.is( author.npmUser, fakeAuthorId );
t.is( author.githubUser, fakeAuthorId );
t.is( author.twitter, fakeAuthorId );
t.end();
} );


test( 'getMaintainers - maintainers is not defined', t => {
let packageJson = {
Expand Down

0 comments on commit c73d829

Please sign in to comment.