Created
February 21, 2018 09:37
-
-
Save bblanchon/4156ea5661293d84dc19d6c192e8da1b to your computer and use it in GitHub Desktop.
Collect text from all licenses in package dependencies
This file contains hidden or 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') | |
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