Created
December 6, 2016 00:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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