@quintype/copyright-header

1.3.4 • Public • Published

Copyright Header

Add or update copyright headers on source code files by scanning directory patterns recursively.

Installation

Global:

npm i @quintype/copyright-header -g

As local devDependency:

npm i @quintype/copyright-header --save-dev

Usage Examples

List of file extensions supported:

copyright-header -ex

Add or update copyright headers:

copyright-header -i "test/files/**/*" -f test/header.js

Options

Usage: copyright-header [options]

Options:
-f, --license-file <file>         copyright license file
-i, --include-path <paths>        recursively insert header in all files found in path (allows multiple file patterns separated by space and within double quotes '"')
-e, --exclude-path <paths>        skip adding headers for files in the path (allows multiple file patterns separated by comma space and within double quotes '"')
-u, --include-git-untracked       include git untracked files, by default git untracked files will be skipped
-s, --git-stage-files             add file changes to git staging
-ex, --supported-file-extensions  list supported file extensions
-V, --version                     output the version number
-h, --help                        display help for command

Copyright license file

  • Copyright license information in this file will be added as header to the source code files.
  • It should be a javascript file (.js) and can have dynamic content using template string.
  • Example license file,
// ************************************************************************
// *  © [2015 - ${new Date().getFullYear()}] Quintype Technologies India Private Limited
// *  All Rights Reserved.
// *************************************************************************

  • Program will read the license info as-is including empty lines after the comment, modify comment syntax based on the target file and append/update it to the target file beginning.
  • For updating a copyright, existing comment in the file should have any of the following keywords, 'copyright', '(c)', '©'
  • Make sure to check exact number of new lines added after the comment using text editors like vim. If using visual editors like vscode, then add an additional new line to the number of one's intended.

List of supported languages/file extensions

c, cpp, js, jsx, ts, tsx, go, java, clj, py

Adding support for new language/file extensions

  • Currently, this is possible only with a library configuration change. No command line option available to extend language support.
  • Add an entry in the library source code file, copyright-header/src/config/index.ts under SUPPORTED_LANGUAGES, similar to the one below
 {
    name: 'Ruby',
    fileExtensions: ['rb'],
    commentSyntax: {
      singleLine: {
        start: ['#']
      }
    }
  }

Configuring as husky pre commit hook

  • Add the following under scripts in package.json file.

"copyright-header": "copyright-header -f copyright-header-template.js -i \"src/**/*" -s"

  • Above script command will add/update copyright header in copyright-header-template.js file to all source code files under src directory.

  • Add the following in husky pre commit hook config in package.json file,

"husky": {
    "hooks": {
      "pre-commit": "npm run copyright-header"
    }
  }

Readme

Keywords

none

Package Sidebar

Install

npm i @quintype/copyright-header

Weekly Downloads

43

Version

1.3.4

License

ISC

Unpacked Size

54.5 kB

Total Files

23

Last publish

Collaborators

  • arunabhthakur94
  • vishwanath.reddy
  • nandakishore
  • ritesh-singh-quintype
  • rahul.joseph
  • himani39
  • veena.yemmiganur
  • jeevan_kishore
  • devops-quintype
  • sharangj
  • athira001
  • srajesh636
  • sivteck
  • shraddha_kesari
  • bindiya
  • ags1773
  • deokumarjnu
  • qtpravin
  • reena07111996
  • nikithanadig
  • harshie46
  • mauliksharma
  • raghavendra.vaidya
  • snitin8994
  • sarvabharan
  • rakshi059
  • enkrypt
  • shriramethiraj
  • g_madhuparna
  • phaneendraandukuri