mhassan1 / yarn-plugin-licenses

Yarn Berry plugin that adds `yarn licenses` commands
42 stars 11 forks source link

[Feature Request] CSV Output #69

Closed davmillar closed 2 months ago

davmillar commented 2 months ago

Howdy. I'm using the nlf package for most of the apps and services I work on to get license information, and I find the CSV output handy for providing to my employer's audit team. It would be nice if this plugin had a similar mode available. Although nlf worked on most of our services, it encountered problems with one of our Yarn-based apps so I'm using this plugin to get the data, but must manually format it now.

mhassan1 commented 2 months ago

This library uses treeUtils.emitTree from @yarnpkg/core, which has no support for CSV. I think it's beyond the scope of this library to support different output formats.

Here's a jq snippet that might work for you:

yarn licenses list --json | jq -r '[.] | map({ license: .value, package: (.children[(.children | keys)[]]) }) | map([ .license, .package.value.locator, .package.value.descriptor, .package.children.url, .package.children.vendorName, .package.children.vendorUrl ])[] | @csv'

You could also use a CLI like @json2csv/cli, if you prefer.