Skip to content

Commit

Permalink
Merge 083985b into 4e8b5c7
Browse files Browse the repository at this point in the history
  • Loading branch information
nexdrew committed Nov 8, 2015
2 parents 4e8b5c7 + 083985b commit 534d72f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"tmp": "0.0.28"
},
"dependencies": {
"all-stars": "^0.1.0",
"es6-promise": "^3.0.2"
}
}
37 changes: 32 additions & 5 deletions util/package.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
'use strict';

var allStars = require( 'all-stars' );

/**
* Check all-stars db for given person and normalize person data if found.
*
* @param {Object|false} person object representing author or maintainer
*
* @return {Object|false} same object given, possibly modified or augmented
*/
function getAllStar( person ) {
if ( !person ) return person;

var allStar = allStars( person );
if ( allStar ) {
// normalize name and email
var name = allStar.name();
var email = allStar.email();
if ( name ) person.name = name;
if ( email ) person.email = email;
// add values only defined in all-stars
person.npm = allStar.npmUser();
person.github = allStar.githubUser();
person.twitter = allStar.twitter();
}
return person;
}

/**
* Parse npm string shorthand into object representation
*
Expand All @@ -10,11 +37,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 @@ -32,9 +59,9 @@ function getAuthor( packageJson ) {
return getPersonObject( packageJson.author );
}

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


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

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

Expand Down
38 changes: 38 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,43 @@ 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 allStarAuthors = authors();
let allStarIndex = index();

let fakeAuthorId = 'PiDude314159265359';

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

allStarIndex[ packageJson.author.name ] = fakeAuthorId;
allStarIndex[ 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.npm, fakeAuthorId );
t.is( author.github, fakeAuthorId );
t.is( author.twitter, fakeAuthorId );
t.end();
} );


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

0 comments on commit 534d72f

Please sign in to comment.