source-licenser
v2.0.6
Published
Add license information to source files.
Downloads
1,137
Readme
Source Licenser
Add license information to source files. Checks target files, looks for existing license content and replaces it if needed. Supports header, footer, json and sibling license file content, with variable substitution and a couple of other useful features.
Usage
Install
npm install [-g] source-licenser
Setup
Define a configuration file as per your needs (see below). You can use the licenser's own config file as a starting point.
Run
source-licenser --config-file <config.yml> <directory>
Example: source-licenser --config-file ./config/licenser-config.yml ./
Configuration file
YAML (used below), JSON and JS are supported.
files:
<pattern>: # e.g. "**/*.js"
<action>: # header, footer, siblingLicenseFile or json
<setting>: <value> # see details of actions below
...
...
...
ignore:
- <pattern> # e.g. git, node_modules
- ...
license: |
<text>
...
substitutions:
<key>: <value>
...
files
Define search patterns for your target files in the files
configuration object (see also ignore
below). Usual glob patterns such as **/*.js
are supported. For each pattern, define the action(s) to be taken:
header
and footer
actions
Respectively prepend or append license content to files. Settings:
startBlock
(string): The starting line(s) of the license block, used to determine if a header already exists. E.g./**\n * @license
linePrefix
(string, optional): A prefix for each line of thelicense
text. E.g.*
endBlock
(string): The ending line(s) of the license block, used to determine where the existing header ends.license
(string, optional): Action-specific license text. Defaults to the rootlicense
setting (see below).
siblingLicenseFile
action
Add a license file at the same level as the matching file(s). Settings:
name
(string): The name of the license file. E.g.LICENSE
license
(string, optional): Action-specific license text. Defaults to the rootlicense
setting (see below).
json
action
Add/update JSON properties (mainly aimed at package.json
). Settings:
force
(key-value, optional): Properties to always set regardless of whether a value already existsdefaults
(key-value, optional): Properties to set if not definedsortPackage
(true
|false
, optional): Ensure a consistent ordering ofpackage.json
properties
ignore
(optional)
List file patterns to be ignored.
license
The license text. Can be overridden in action settings.
substitutions
(optional)
Define variables that can be used in license
or action settings with the format {NAME}
. The following helper variables are built in (but can be overridden):
CURRENT_YEAR
simply evaluates to the current (full) year, e.g.2022
YEARS
, when configured withstart
andend
values, evaluates toend
ifstart
==end
, and tostart–end
otherwise.end
accepts the valueCURRENT_YEAR
. For example:substitutions: YEARS: start: 2020 end: CURRENT_YEAR
Contributing
npm test
runs the tests with Mocha.
npm run test-cover
runs the tests and outputs coverage stats with Istanbul.
npm run license-me
runs source-licenser on itself.
The code follows the Semi-Standard style.