Skip to content

Instantly share code, notes, and snippets.

@Macmee
Created December 6, 2016 00:51
Show Gist options
  • Save Macmee/fd0c6f78b6079a4cec88f2992a471fb4 to your computer and use it in GitHub Desktop.
Save Macmee/fd0c6f78b6079a4cec88f2992a471fb4 to your computer and use it in GitHub Desktop.
place this in a folder containing git repos (i.e. stick it in a node_modules folder or the parent folder for all your git repos) and run `node find-licenses` and it will be happy
const fs = require('fs'),
path = require('path');
function getDirectories(srcpath) {
return fs.readdirSync(srcpath).filter(function(file) {
return fs.statSync(path.join(srcpath, file)).isDirectory();
});
}
getDirectories('.').forEach(folder => {
try {
var package = JSON.parse(fs.readFileSync(`./${folder}/package.json`, 'utf8'));
var deps = Object.keys(package.dependencies || {});
var devdeps = Object.keys(package.devDependencies || {});
[].push.apply(deps, devdeps);
console.log(folder + ' found:');
deps.forEach(project => {
var contents = JSON.parse(fs.readFileSync(`./${folder}/node_modules/${project}/package.json`, 'utf8'));
if (contents.license) console.log(project, contents.license);
});
console.log('\n\n' + folder + ' missing:');
deps.forEach(project => {
var contents = JSON.parse(fs.readFileSync(`./${folder}/node_modules/${project}/package.json`, 'utf8'));
if (!contents.license) console.log(project);
});
console.log('\n\n');
}catch(e) {
// console.log(e)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment