Comparing version 0.0.1 to 0.1.0
123
index.js
@@ -7,106 +7,33 @@ 'use strict' | ||
module.exports = async ({ dev = false, peer = false } = {}) => { | ||
const modules = await licenseSearch() | ||
const anderson = await readAnderson() | ||
const { | ||
dependencies, | ||
devDependencies, | ||
peerDependencies | ||
} = await getDependencies({ dev, peer }) | ||
module.exports = async () => { | ||
const { blacklist } = await readAnderson() | ||
const { dependencies } = await getDependencies() | ||
const licenses = await licenseSearch() | ||
const pkgs = [] | ||
let result = [] | ||
licenses.filter(license => { | ||
return dependencies.filter(dependency => { | ||
if (license.pkg.name === dependency.name) { | ||
const hasList = blacklist ? blacklist : undefined | ||
const contraband = hasList | ||
? blacklist.indexOf(license.pkg.license) !== -1 | ||
: false | ||
const pkg = Object.assign( | ||
{}, | ||
{ | ||
name: license.pkg.name, | ||
version: license.pkg.version, | ||
license: license.pkg.license, | ||
contraband | ||
} | ||
) | ||
modules.forEach(module => { | ||
dependencies.forEach(dependency => { | ||
if (module.pkg.name === dependency.name) { | ||
if (anderson && anderson.whitelist) { | ||
anderson.whitelist.forEach(license => { | ||
if (module.pkg.license !== license) { | ||
return (dependency.contraband = true) | ||
} | ||
return pkgs.push(pkg) | ||
} | ||
return (dependency.contraband = false) | ||
}) | ||
} | ||
if (anderson && anderson.blacklist) { | ||
anderson.blacklist.forEach(license => { | ||
if (module.pkg.license === license) { | ||
return (dependency.contraband = true) | ||
} | ||
return (dependency.contraband = false) | ||
}) | ||
} | ||
dependency.license = module.pkg.license | ||
return dependency | ||
} | ||
return false | ||
}) | ||
if (dev) { | ||
devDependencies.forEach(dependency => { | ||
if (module.pkg.name === dependency.name) { | ||
if (anderson && anderson.whitelist) { | ||
anderson.whitelist.forEach(license => { | ||
if (module.pkg.license !== license) { | ||
return (dependency.contraband = true) | ||
} | ||
return (dependency.contraband = false) | ||
}) | ||
} | ||
if (anderson && anderson.blacklist) { | ||
anderson.blacklist.forEach(license => { | ||
if (module.pkg.license === license) { | ||
return (dependency.contraband = true) | ||
} | ||
return (dependency.contraband = false) | ||
}) | ||
} | ||
dependency.license = module.pkg.license | ||
return dependency | ||
} | ||
}) | ||
} | ||
if (peer) { | ||
peerDependencies.forEach(dependency => { | ||
if (module.pkg.name === dependency.name) { | ||
if (anderson && anderson.whitelist) { | ||
anderson.whitelist.forEach(license => { | ||
if (module.pkg.license !== license) { | ||
return (dependency.contraband = true) | ||
} | ||
return (dependency.contraband = false) | ||
}) | ||
} | ||
if (anderson && anderson.blacklist) { | ||
anderson.blacklist.forEach(license => { | ||
if (module.pkg.license === license) { | ||
return (dependency.contraband = true) | ||
} | ||
return (dependency.contraband = false) | ||
}) | ||
} | ||
dependency.license = module.pkg.license | ||
return dependency | ||
} | ||
}) | ||
} | ||
}) | ||
result = [...result, ...dependencies, ...devDependencies, ...peerDependencies] | ||
return result | ||
return pkgs | ||
} |
{ | ||
"name": "anderson", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Checks your node dependencies for contraband licenses", | ||
@@ -21,18 +21,17 @@ "main": "index.js", | ||
], | ||
"dependencies": { | ||
"js-yaml": "^3.8.4", | ||
"read-package": "^0.0.1" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.19.1", | ||
"eslint-config-prettier": "^2.6.0", | ||
"xo": "^0.18.2" | ||
}, | ||
"dependencies": { | ||
"js-yaml": "^3.8.4", | ||
"read-package": "^0.0.1" | ||
}, | ||
"xo": { | ||
"space": true, | ||
"semicolon": false, | ||
"esnext": true, | ||
"extends": [ | ||
"prettier" | ||
], | ||
"rules": { | ||
"object-curly-spacing": 0, | ||
"no-prototype-builtins": 0, | ||
"no-return-assign": 0 | ||
"no-prototype-builtins": 0 | ||
} | ||
@@ -39,0 +38,0 @@ }, |
@@ -5,3 +5,2 @@ # anderson [![Build Status](https://travis-ci.org/bukinoshita/anderson.svg?branch=master)](https://travis-ci.org/bukinoshita/anderson) | ||
_Feel free to contribute to this project to improve the code._ | ||
@@ -19,3 +18,3 @@ ## Install | ||
anderson() | ||
await anderson() | ||
@@ -46,3 +45,3 @@ /* | ||
_anderson is heavily inspired on [anderson](https://github.com/contraband/anderson)_ | ||
_anderson is heavily inspired on [anderson](https://github.com/contraband/anderson)._ | ||
@@ -52,25 +51,7 @@ | ||
### anderson([options]) | ||
### anderson() | ||
returns an `array` | ||
returns a `promise` | ||
#### options | ||
Type: `object` | ||
##### dev | ||
Type: `boolean`<br/> | ||
Default: false | ||
If `true` it will check dev-dependencies | ||
##### peer | ||
Type: `boolean`<br/> | ||
Default: false | ||
If `true` it will check peer-dependencies | ||
## Related | ||
@@ -77,0 +58,0 @@ |
'use strict' | ||
import test from 'ava' | ||
import m from './' | ||
import m from '.' | ||
@@ -6,0 +6,0 @@ test(async t => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
128178
3
11
114
61