Skip to content

Commit

Permalink
Merge 739faf6 into 6dd7fb1
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypercubed committed Oct 12, 2016
2 parents 6dd7fb1 + 739faf6 commit 927deac
Show file tree
Hide file tree
Showing 28 changed files with 316 additions and 77 deletions.
37 changes: 25 additions & 12 deletions lib/analyzers/bower/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ var globby = require( 'globby' );
var creditUtil = require( '../../credit' );
var packageUtil = require( '../../package' );

/**
* Read and evaluate dependency credits for bower module
*
* @param {String} bowerJsonPath absolute path to bower file
* @param {Array} credits list of credits to append to
* @return {Array} list of credits
*/
function getBowerCredits( bowerJsonPath, credits ) {
var name = path.basename( path.dirname( bowerJsonPath ) );
var bowerJson = require( bowerJsonPath );

var authors = packageUtil.getAuthor( bowerJson );

if ( authors ) {
authors.forEach( function( author ) {
credits = creditUtil.addCreditToCredits( credits, author, name );
} );
}

return credits;
}

/**
* Read project root and evaluate dependency credits for bower modules
Expand All @@ -15,26 +36,18 @@ var packageUtil = require( '../../package' );
*
* @return {Array} list of credits
*/
function getCredits( projectPath ) {
var credits = [];
function getCredits( projectPath, credits ) {
credits = credits || [];

var depPath = path.join( projectPath, 'bower_components' );

globby.sync( [ `${depPath}/*/bower.json` ] )
.forEach( function( bowerJsonPath ) {
var name = path.basename( path.dirname( bowerJsonPath ) );
var bowerJson = require( bowerJsonPath );

var authors = packageUtil.getAuthor( bowerJson );

if ( authors ) {
authors.forEach( function( author ) {
credits = creditUtil.addCreditToCredits( credits, author, name );
} );
}
getBowerCredits( bowerJsonPath, credits );
} );

return credits;
}

module.exports = getCredits;
module.exports.getBowerCredits = getBowerCredits;
28 changes: 9 additions & 19 deletions lib/analyzers/jspm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var globby = require( 'globby' );

var creditUtil = require( '../../credit' );
var packageUtil = require( '../../package' );
var getNpmCredits = require( '../npm' ).getNpmCredits;
var getBowerCredits = require( '../bower' ).getBowerCredits;

/**
* Read project root and evaluate dependency credits for jspm modules
Expand All @@ -14,29 +16,17 @@ var packageUtil = require( '../../package' );
*
* @return {Array} list of credits
*/
function getCredits( projectPath ) {
var credits = [];
function getCredits( projectPath, credits ) {
credits = credits || [];

var jspmPath = path.join( projectPath, 'jspm_packages' );

globby.sync( [ `${jspmPath}/npm/*/package.json`, `${jspmPath}/github/*/*/package.json` ] )
globby.sync( [ `${jspmPath}/npm/*/package.json`, `${jspmPath}/github/*/*/{package.json,bower.json}` ] )
.forEach( function( packagePath ) {
var name = path.basename( path.dirname( packagePath ) );

if ( name[ 0 ] !== '.' && name.indexOf( '.js' ) === -1 ) {
var packageJson = require( path.join( packagePath ) );
var author = packageUtil.getAuthor( packageJson );
var maintainers = packageUtil.getMaintainers( packageJson );

if ( author ) {
credits = creditUtil.addCreditToCredits( credits, author, name );
}

if ( maintainers ) {
maintainers.forEach( function( maintainer ) {
credits = creditUtil.addCreditToCredits( credits, maintainer, name );
} );
}
if ( path.basename( packagePath ) === 'bower.json' ) {
return getBowerCredits( packagePath, credits );
}
return getNpmCredits( packagePath, credits );
} );

return credits;
Expand Down
62 changes: 38 additions & 24 deletions lib/analyzers/npm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,42 @@ var globby = require( 'globby' );
var creditUtil = require( '../../credit' );
var packageUtil = require( '../../package' );

/**
* Read and evaluate dependency credits for npm module
*
* @param {String} packagePath absolute path to package.json file
* @param {Array} credits list of credits to append to
* @return {Array} list of credits
*/
function getNpmCredits( packagePath, credits ) {
var directoryPath = path.dirname( packagePath );
var name = path.basename( path.dirname( packagePath ) );

if (
name[ 0 ] !== '.' &&
(
fs.lstatSync( directoryPath ).isDirectory() ||
fs.lstatSync( directoryPath ).isSymbolicLink()
)
) {
var packageJson = require( packagePath );
var author = packageUtil.getAuthor( packageJson );
var maintainers = packageUtil.getMaintainers( packageJson );

if ( author ) {
credits = creditUtil.addCreditToCredits( credits, author, name );
}

if ( maintainers ) {
maintainers.forEach( function( maintainer ) {
credits = creditUtil.addCreditToCredits( credits, maintainer, name );
} );
}
}

return credits;
}

/**
* Read project root and evaluate dependency credits for node modules
*
Expand All @@ -23,33 +59,11 @@ function getCredits( projectPath, credits ) {

globby.sync( `${depPath}/**/package.json` )
.forEach( function( packagePath ) {
var directoryPath = path.dirname( packagePath );
var name = path.basename( path.dirname( packagePath ) );

if (
name[ 0 ] !== '.' &&
(
fs.lstatSync( directoryPath ).isDirectory() ||
fs.lstatSync( directoryPath ).isSymbolicLink()
)
) {
var packageJson = require( packagePath );
var author = packageUtil.getAuthor( packageJson );
var maintainers = packageUtil.getMaintainers( packageJson );

if ( author ) {
credits = creditUtil.addCreditToCredits( credits, author, name );
}

if ( maintainers ) {
maintainers.forEach( function( maintainer ) {
credits = creditUtil.addCreditToCredits( credits, maintainer, name );
} );
}
}
getNpmCredits( packagePath, credits );
} );

return credits;
}

module.exports = getCredits;
module.exports.getNpmCredits = getNpmCredits;
11 changes: 10 additions & 1 deletion test/fixtures/bower_components/bar/bower.json
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
{"authors":[{"name":"Alice Bobson","email":"alicebobson@alison.io"}]}
{
"name": "bar",
"authors": [
{"name":"Alice Bobson","email":"alicebobson@alison.io"}
],
"description": "",
"main": "",
"license": "MIT",
"private": true
}
9 changes: 8 additions & 1 deletion test/fixtures/bower_components/boom/bower.json
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{"note":"no authors"}
{
"name": "boom",
"note": "no authors",
"description": "",
"main": "",
"license": "MIT",
"private": true
}
11 changes: 10 additions & 1 deletion test/fixtures/bower_components/foo/bower.json
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
{"authors":["Bob Calsow"]}
{
"name": "foo",
"authors": [
"Bob Calsow"
],
"description": "",
"main": "",
"license": "MIT",
"private": true
}
10 changes: 10 additions & 0 deletions test/fixtures/jspm_packages/github/calsow/foo/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "foo",
"authors": [
"Bob Calsow"
],
"description": "",
"main": "",
"license": "MIT",
"private": true
}
1 change: 0 additions & 1 deletion test/fixtures/jspm_packages/github/calsow/foo/package.json

This file was deleted.

10 changes: 10 additions & 0 deletions test/fixtures/jspm_packages/github/components/bar/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "bar",
"authors": [
{"name":"Alice Bobson","email":"alicebobson@alison.io"}
],
"description": "",
"main": "",
"license": "MIT",
"private": true
}
12 changes: 12 additions & 0 deletions test/fixtures/jspm_packages/github/components/bar/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"author": "Alice Bobson",
"name": "bar",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"license": "ISC",
"description": ""
}

This file was deleted.

1 change: 0 additions & 1 deletion test/fixtures/jspm_packages/npm/.bin/package.json

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions test/fixtures/jspm_packages/npm/.cache/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"note": "this should be ignored",
"author": "Alice Bobson",
"name": "cache",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"license": "ISC",
"description": ""
}
17 changes: 16 additions & 1 deletion test/fixtures/jspm_packages/npm/baz/package.json
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
{"author":"Alice Bobson","maintainers":["Randy Ran",{"name":"Bobby Bob","email":"bobby@bob.io"}]}
{
"author": "Alice Bobson",
"maintainers": [
"Randy Ran",
"Bobby Bob <bobby@bob.io>"
],
"name": "baz",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"license": "ISC",
"description": ""
}
12 changes: 11 additions & 1 deletion test/fixtures/jspm_packages/npm/boing/package.json
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
{"author":"Bob Calsow <bob@calsow.io>"}
{
"author": "Bob Calsow <bob@calsow.io>",
"name": "boing",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "ISC",
"description": ""
}
13 changes: 12 additions & 1 deletion test/fixtures/jspm_packages/npm/boo/package.json
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
{"author":"Janice Robson"}
{
"author": "Janice Robson",
"name": "boo",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"license": "ISC",
"description": ""
}
12 changes: 11 additions & 1 deletion test/fixtures/linked/package.json
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
{"author":"Bob Loblaw"}
{
"author": "Bob Loblaw",
"name": "linked",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "ISC",
"description": ""
}
1 change: 0 additions & 1 deletion test/fixtures/node_modules/.bin/package.json

This file was deleted.

13 changes: 13 additions & 0 deletions test/fixtures/node_modules/.cache/node_modules/cached/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions test/fixtures/node_modules/.cache/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion test/fixtures/node_modules/bar/node_modules/boom/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 927deac

Please sign in to comment.