Skip to content

Instantly share code, notes, and snippets.

@bblanchon
Created February 21, 2018 09:37
Show Gist options
  • Save bblanchon/4156ea5661293d84dc19d6c192e8da1b to your computer and use it in GitHub Desktop.
Save bblanchon/4156ea5661293d84dc19d6c192e8da1b to your computer and use it in GitHub Desktop.
Collect text from all licenses in package dependencies
const fs = require('fs')
const path = require('path')
var licenses = []
var node_modules = path.resolve('./frontend/node_modules')
var meta = JSON.parse(fs.readFileSync('./frontend/package.json', 'utf8'))
for( var module in meta.dependencies ) {
try {
var license = fs.readFileSync(path.resolve(node_modules, module, 'LICENSE'), 'utf8')
var meta = JSON.parse(fs.readFileSync(path.resolve(node_modules, module, 'package.json'), 'utf8'))
licenses.push({
name: meta.name,
text: license
})
}
catch(e) {
console.log(`Skip ${module} (${e.message})`)
}
}
fs.writeFileSync('./licenses.json', JSON.stringify(licenses, null, ' '))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment