Reputation: 494
In my node_modules folder, let's say that I have 5 folders:
Folder1
Folder2
Folder3
Folder4
Folder5
Each folder contains a "LICENSE" file or "LICENSE.md" file. I want to run a script of some kind whether it be Python or JS that takes the contents of each LICENSE file along with name of package and add it to one single file "Destination.txt". Is there an easier way to do this? I know that NPM License Checker allows me to list licenses and then I can output the results into a text file, but I also want to see the contents of each LICENSE file into a single file.
So sample output for Destination.txt should be like:
Folder1
text from LICENSE file
Folder2
text from LICENSE file
Folder3
text from LICENSE file
Folder4
text from LICENSE file
Folder5
text from LICENSE file
What I'm thinking about is possibly a Python script that traverses each folder in node_modules and tries to find a LICENSE file. When it goes into a folder and finds a LICENSE, it copies / pastes the contents into Destination.txt and then moves on to the next LICENSE file. I'm not sure how to implement this and would appreciate any tips. Doesn't have to be Python. I'm on a Windows computer so if there's a creative way to use the CLI commands to generate what I'm looking for, that'd be great.
TLDR; I want to list the names of my packages as well as the contents of their associated LICENSE files all in one file. So if package1 is listed, the contents of the package1 LICENSE file will be listed below it. Same with package2 and so on.
Upvotes: 1
Views: 1470
Reputation: 7358
The generate-license-file package does exactly what you need:
% npx generate-license-file --input package.json --output 3rd-party.txt
% cat 3rd-party.txt
This file was generated with the generate-license-file npm package!
https://www.npmjs.com/package/generate-license-file
The following npm package may be included in this product:
- @babel/[email protected]
This package contains the following license and notice below:
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-----------
The following npm packages may be included in this product:
- @floating-ui/[email protected]
- @floating-ui/[email protected]
- @floating-ui/[email protected]
These packages each contain the following license and notice below:
MIT License
Upvotes: 1
Reputation: 494
The closest thing I've been able to find that doesn't require a custom script is Yarn Licenses.
I used command yarn licenses generate-disclaimer > output.txt
It worked even though I have never installed anything via Yarn before. Only NPM.
Upvotes: 2
Reputation: 10122
most languages has a package that already does that. e.g.
nodejs:
python:
ruby:
each of which has ability to produce a json file, which you can then parse and combine as you wish.
if you specifically interested in npm packages, then just use npm view
like so
$ npm view eslint --json license
"MIT"
and if you want it to all your npm packages, then you can combine it with npm ls
like so
for PKG in $(npm ls --json | jq -r '.dependencies | keys | .[]')
do
npm view $PKG name license --json
done
Upvotes: 0