Skip to content

Commit

Permalink
Introduce a license aggregator for dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
timaschew committed Jul 8, 2016
1 parent 5d3d506 commit 14b73c8
Show file tree
Hide file tree
Showing 4 changed files with 357 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -35,3 +35,5 @@ npm-shrinkwrap.json

# IDE configuration
.idea

licenses.json
6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -14,7 +14,8 @@
"watch": "node node_modules/watch/cli.js \"npm test\" ./src ./test",
"reporter": "node jasmine-runner",
"test": "jasmine JASMINE_CONFIG_PATH=jasmine.json",
"test-http-server": "node test/test-helper/start-test-server.js"
"test-http-server": "node test/test-helper/start-test-server.js",
"license": "mkdir -p build && node scripts/license-aggregator > build/LICENSE && cat scripts/resources/missing-licenses.txt >> build/LICENSE"
},
"repository": {
"type": "git",
Expand All @@ -34,15 +35,16 @@
"needle": "^1.0.0"
},
"devDependencies": {
"async": "^0.2.9",
"coveralls": "^2.11.9",
"engine.io-client": "^1.6.11",
"grunt": "^1.0.1 ",
"grunt-release": "^0.14.0",
"istanbul": "^0.4.3",
"jasmine": "^2.4.1",
"nexe": "^1.1.2",
"jasmine-spec-reporter": "^2.5.0",
"n0p3": "^1.0.2",
"nexe": "^1.1.2",
"proxyquire": "1.7.10",
"watch": "^0.19.1"
},
Expand Down
221 changes: 221 additions & 0 deletions scripts/license-aggregator.js
@@ -0,0 +1,221 @@
#!/usr/bin/env node

'use strict'

const path = require('path')
const fs = require('fs')
const child_process = require('child_process')
const async = require('async')

const PRE_HEADER = fs.readFileSync('LICENSE', 'utf8')
const HEADER = `
This license applies to all parts of deepstream.io that are not externally
maintained libraries.
The externally maintained libraries used by deepstream.io are:
`
const emptyState = "see MISSING LICENSES at the bottom of this file";


if (path.basename(process.cwd()) === 'scripts') {
console.error('Run this script from the project root!')
process.exit(0)
}

child_process.execSync('npm list --production --json > licenses.json')
const mainModule = require('../licenses.json')

const moduleNames = []
traverseDependencies(mainModule)

function traverseDependencies(module) {
for (let dependency in module.dependencies) {
moduleNames.push(dependency)
traverseDependencies(module.dependencies[dependency])
}
}

// This source code is taken from the 'license-spelunker' npm module, it was patched

/*
The MIT License (MIT)
Copyright (c) 2013 Mike Brevoort
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
var projPath = path.resolve(process.argv[2] || '.');
console.error('Project Path', projPath);
var topPkg = require(path.join(projPath, 'package.json'));

var modules = [];
var count = 0;

doLevel(projPath);


function doLevel(nodePath) {
var pkg = require(path.join(nodePath, 'package.json'));
if (topPkg.name !== pkg.name && moduleNames.indexOf(pkg.name) === -1) {
return
}
var nodeModulesPath = path.join(nodePath, 'node_modules');
count ++;

//console.error('package.json license', pkg.license);

fs.exists(nodeModulesPath, function (dirExists) {
if (dirExists) {
fs.readdir(nodeModulesPath, function (err, files) {
if (err) throw err;
var directories = [];
files = files.map(function (f) { return path.join(nodeModulesPath, f); })
async.filter(files, isModuleDirectory, function(directories){
// console.error('module directories', directories);
directories.forEach(doLevel);
});
})
}
})

licenseText(nodePath, function (license) {
var licenceProperty = pkg.license || pkg.licenses
var licenceUrl = (pkg.license || {}).url
if ((licenceProperty || {}).type) {
licenceProperty = licenceProperty.type
licenceUrl = licenceProperty[0].url
}
if (((licenceProperty || {})[0] || []).type) {
licenceProperty = licenceProperty[0].type
licenceUrl = licenceProperty[0].url
}

if (pkg.name !== topPkg.name) {
modules.push({
name: pkg.name,
version: pkg.version,
url: 'http://npmjs.org/package/' + pkg.name,
localPath: path.relative(projPath,nodePath),
pkgLicense: licenceProperty,
licenceUrl: licenceUrl,
license: license
});
}
count--;

if (count == 0) {
var noLicenseFile = modules.filter(function (m) { return m.license === emptyState });
var andNoPkgJsonLicense = noLicenseFile.filter(function (m) { return !m.pkgLicense });

// Status report
// Write to StdErr
console.error('LICENSE FILE REPORT FOR ', topPkg.name);
console.error(modules.length + ' nested dependencies')
console.error(noLicenseFile.length + ' without identifiable license text')
console.error(andNoPkgJsonLicense.length + ' without even a package.json license declaration', '\n\n')

// Write to StdOut
console.log(PRE_HEADER)
console.log('')
console.log(HEADER)
modules.forEach(function(m) {
console.log((modules.indexOf(m)+1) + ' ----------------------------------------------------------------------------');
console.log(m.name + '@' + m.version);
console.log(m.url);
console.log(m.localPath);
if (m.pkgLicense) console.log('From package.json license property:', JSON.stringify(m.pkgLicense));
if (m.licenceUrl) console.log('From package.json url property:', JSON.stringify(m.licenceUrl));
console.log('');
console.log(m.license);
console.log('');
})
}
})
}

function licenseText (nodePath, cb) {
var possibleLicensePaths = [
path.join(nodePath, 'LICENSE'),
path.join(nodePath, 'LICENCE'),
path.join(nodePath, 'LICENSE.md'),
path.join(nodePath, 'LICENSE.txt'),
path.join(nodePath, 'LICENSE-MIT'),
path.join(nodePath, 'LICENSE-BSD'),
path.join(nodePath, 'LICENSE.BSD'),
path.join(nodePath, 'MIT-LICENSE.txt'),
path.join(nodePath, 'Readme.md'),
path.join(nodePath, 'README.md'),
path.join(nodePath, 'README.markdown')
];

async.reduceRight(possibleLicensePaths, emptyState, function (state, licensePath, reduceCb) {
var isAReadme = (licensePath.toLowerCase().indexOf('/readme') > 0);

// if we already found a licnese, don't bother looking at READMEs
if (state !== emptyState && isAReadme) return reduceCb (null, state);

fs.exists(licensePath, function (exists) {
if (!exists) return reduceCb(null, state);
fs.readFile(licensePath, { encoding: 'utf8' }, function (err, text) {
if (err) return logError(err, reduceCb)(err, state);

if (isAReadme) {
var match = text.match(/\n[# ]*license[ \t]*\n/i);
if (match) {
//console.log(match.input.substring(match.index))
return reduceCb (null, 'FROM README:\n' + match.input.substring(match.index));
}
else {
return reduceCb(null, state);
}
}
else {
return reduceCb (null, text);
}


return reduceCb (null, text);
})

});
}, function (err, license) {
if (err) return cb('ERROR FINDING LICENSE FILE ' + err );
cb (license);
});
}

function isModuleDirectory (dirPath, cb) {
var pkgPath = path.join(dirPath, 'package.json');
fs.stat(dirPath, function (err, stat) {
if (err) return logError(err, cb)(false);

var isdir = stat.isDirectory();
if (isdir) {
fs.exists(pkgPath, cb);
}
else {
cb(false);
}
});
}

function logError(err, cb) {
console.error('ERROR', err);
return cb
}
130 changes: 130 additions & 0 deletions scripts/resources/missing-licenses.txt
@@ -0,0 +1,130 @@
----------------------------------------------------------------------------

MISSING LICENSES

----------------------------------------------------------------------------
adm-zip@0.4.7
http://npmjs.org/package/adm-zip
node_modules/adm-zip
From package.json license property: "MIT"

Copyright (c) 2012 Another-D-Mention Software and other contributors,
http://www.another-d-mention.ro/

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

----------------------------------------------------------------------------
base64id@0.1.0
http://npmjs.org/package/base64id
node_modules/engine.io/node_modules/base64id

(The MIT License)

Copyright (c) 2012 Kristian Faeldt <faeldt_kristian@cyberagent.co.jp>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

----------------------------------------------------------------------------
blob@0.0.4
http://npmjs.org/package/blob
node_modules/engine.io/node_modules/engine.io-parser/node_modules/blob

MIT License

Copyright (C) 2014 Rase-

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

----------------------------------------------------------------------------
base64-arraybuffer@0.1.2
http://npmjs.org/package/base64-arraybuffer
node_modules/engine.io/node_modules/engine.io-parser/node_modules/base64-arraybuffer
From package.json license property: "MIT"

Copyright (c) 2012 Niklas von Hertzen

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

----------------------------------------------------------------------------
options@0.0.6
http://npmjs.org/package/options
node_modules/engine.io/node_modules/ws/node_modules/options

(The MIT License)

Copyright (c) 2012 Einar Otto Stangvik <einaros@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 comments on commit 14b73c8

Please sign in to comment.