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
underSUPPORTED_LANGUAGES
, similar to the one below
{
name: 'Ruby',
fileExtensions: ['rb'],
commentSyntax: {
singleLine: {
start: ['#']
}
}
}
Configuring as husky pre commit hook
- Add the following under
scripts
inpackage.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 undersrc
directory. -
Add the following in husky pre commit hook config in
package.json
file,
"husky": {
"hooks": {
"pre-commit": "npm run copyright-header"
}
}