Skip to content

Generate a file with license text from NPM dependencies

License

Notifications You must be signed in to change notification settings

tech-meppem/npm-license-generator

 
 

Repository files navigation

NPM License Generator

Generate a page with a copy of NPM dependency licenses. Example output

Usage

Install:

npm install --global npm-license-generator

Options:

$ npm-license-generator --help

Usage:
  npm-license-generator [folder]

Positionals:
  folder  Folder of NPM project. Defaults to current working directory  [string]

Options:
  --version          Show version number                               [boolean]
  --help             Show help                                         [boolean]
  --out-path         HTML output path      [string] [default: "./licenses.html"]
  --registry         URL of package registry to use
                                [string] [default: "https://registry.npmjs.org"]
  --tmp-folder-name  Name of temporary folder
                                          [string] [default: ".license-gen-tmp"]
  --template         Path to custom mustache template                   [string]
  --no-group         Do not group licenses            [boolean] [default: false]
  --package-lock     Run on all packages listed in package-lock.json
                                                      [boolean] [default: false]
  --no-spdx          Do not download license file based on SPDX string
                                                      [boolean] [default: false]
  --only-spdx        Do not download tarballs, only use SPDX string
                                                      [boolean] [default: false]
  --error-missing    Exit 1 if no license is present for a package
                                                      [boolean] [default: false]

Use your own template

Supply your own template using the --template option. Templates are written in Mustache. Your template does not have to be HTML, change the output file name using --out-path.

By default, Mustache is given two variables:

  • name: the package name
  • renderLicenses: an array of GroupedLicense. When using --no-group, an array of LicenseInfo is passed instead.

Check the lib folder for example templates.

How licenses are found

  1. Get package version and tarball location from package.lock
  2. Look for licenses in node_modules if avalible
  3. Otherwise download tarball, extract, look for licenses, and use that
  4. Otherwise, evaluate SPDX string and use a file from https://github.com/spdx/license-list-data/tree/master/text

About

Generate a file with license text from NPM dependencies

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 84.1%
  • HTML 13.4%
  • JavaScript 2.5%