Skip to content

Instantly share code, notes, and snippets.

@formatkaka
Created July 31, 2018 08:57
Show Gist options
  • Save formatkaka/36e92fccc4800949362a11cd94322ba5 to your computer and use it in GitHub Desktop.
Save formatkaka/36e92fccc4800949362a11cd94322ba5 to your computer and use it in GitHub Desktop.
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