npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

source-licenser

v2.0.6

Published

Add license information to source files.

Downloads

1,137

Readme

Source Licenser

CI npm

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 the license 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 root license 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 root license 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 exists
  • defaults (key-value, optional): Properties to set if not defined
  • sortPackage (true|false, optional): Ensure a consistent ordering of package.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 with start and end values, evaluates to end if start == end, and to start–end otherwise. end accepts the value CURRENT_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.

License

BSD-3-Clause