Created
July 31, 2018 08:57
-
-
Save formatkaka/36e92fccc4800949362a11cd94322ba5 to your computer and use it in GitHub Desktop.
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 nlf = require('nlf'); | |
const fs = require('fs'); | |
// const stream = fs.createWriteStream('my_file.txt'); | |
// to only include production dependencies | |
const filename = process.env.PUBLIC_DIR + 'licenses.json'; | |
fs.writeFile(filename, '', () => { | |
console.log('done'); | |
}); | |
const depsArr = []; | |
nlf.find( | |
{ | |
directory: './', | |
production: true | |
}, | |
(err, data) => { | |
data.forEach(project => { | |
const { name } = project; | |
const { licenseSources } = project; | |
if (licenseSources.license && licenseSources.package.sources['0'] && licenseSources.license.sources['0']) { | |
const { text } = licenseSources.license.sources['0']; | |
const { license } = licenseSources.package.sources['0']; | |
const z = { | |
name, | |
license, | |
text | |
}; | |
depsArr.push(z); | |
} | |
}); | |
const obj = { licenses: depsArr }; | |
fs.writeFile(filename, JSON.stringify(obj), err => { | |
console.log('err : ', err); | |
}); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment