Skip to content

Instantly share code, notes, and snippets.

@mjul
Created June 27, 2019 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjul/ccffb6c30cc808b07f198d2353727d64 to your computer and use it in GitHub Desktop.
Save mjul/ccffb6c30cc808b07f198d2353727d64 to your computer and use it in GitHub Desktop.
Get licenses for npm packages in node_modules
write-host "Scanning..."
$packages = Get-ChildItem .\node_modules -Filter 'package.json' -Recurse
write-host ("Found {0} packages." -f $packages.Count)
$licenses = @()
write-host "Reading licenses..."
foreach ($p in $packages) {
$file = $p.FullName
$data = Get-Content -Path $file | ConvertFrom-Json
$license = $data.license
$licenses += $license;
}
$uniques = $licenses | sort-object | Get-Unique | sort-object
write-host ("Found {0} unique licenses." -f $uniques.Count)
$uniques | % { write-host $_ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment