|
| 1 | +# grunt-check-copyright |
| 2 | + |
| 3 | +> Grunt plugin to check if copyright is present in files |
| 4 | +
|
| 5 | +## Getting Started |
| 6 | +This plugin requires Grunt `~0.4.5` |
| 7 | + |
| 8 | +If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: |
| 9 | + |
| 10 | +```shell |
| 11 | +npm install grunt-check-copyright --save-dev |
| 12 | +``` |
| 13 | + |
| 14 | +Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: |
| 15 | + |
| 16 | +```js |
| 17 | +grunt.loadNpmTasks('grunt-check-copyright'); |
| 18 | +``` |
| 19 | + |
| 20 | +## The "check_copyright" task |
| 21 | + |
| 22 | +### Overview |
| 23 | +In your project's Gruntfile, add a section named `check_copyright` to the data object passed into `grunt.initConfig()`. |
| 24 | + |
| 25 | +```js |
| 26 | +grunt.initConfig({ |
| 27 | + check_copyright: { |
| 28 | + options: { |
| 29 | + // Task-specific options go here. |
| 30 | + }, |
| 31 | + your_target: { |
| 32 | + // Target-specific file lists and/or options go here. |
| 33 | + }, |
| 34 | + }, |
| 35 | +}); |
| 36 | +``` |
| 37 | + |
| 38 | +### Options |
| 39 | + |
| 40 | +#### options.copyrights |
| 41 | +Type: `Array` |
| 42 | +Default value: `[/(Copyright .*\. All Rights Reserved\.)/]` |
| 43 | + |
| 44 | +An array containing the various copyrights to check in the list of files specified. |
| 45 | + |
| 46 | +#### options.lines |
| 47 | +Type: `Number` |
| 48 | +Default value: `5` |
| 49 | + |
| 50 | +A number value that is used to check a file first 'n' lines for the copyright. |
| 51 | + |
| 52 | +### Usage Examples |
| 53 | + |
| 54 | +#### Default Options |
| 55 | +In this example, the default options are used to do something with whatever. So if the `fixtures` folder has the files `fail.html`, `fail.js`, `pass.html` and `pass.js`, the file options only filters for the `js` files as per the pattern and the generated result in this case would be `fail.js` since this file doesn't have the copyright notice. |
| 56 | + |
| 57 | +Note: Here we use the default options for lines and copyright as specified [here](#options). |
| 58 | + |
| 59 | +```js |
| 60 | +grunt.initConfig({ |
| 61 | + check_copyright: { |
| 62 | + options: { |
| 63 | + }, |
| 64 | + files: { |
| 65 | + 'default_options': ['test/fixtures/*.js'] |
| 66 | + } |
| 67 | + }, |
| 68 | +}); |
| 69 | +``` |
| 70 | + |
| 71 | +#### Custom Options |
| 72 | +In this example, custom options are used to do something else with whatever else. So if the `fixtures` folder has the files `fail.html`, `fail.js`, `pass.html` and `pass.js`, the file options only filters for the `html` files as per the pattern and the generated result in this case would be `fail.html` since this file doesn't have the copyright notice. |
| 73 | + |
| 74 | +Also, you can see that the `copyrights` array is trying to match two different format of copyright. |
| 75 | + |
| 76 | +```js |
| 77 | +grunt.initConfig({ |
| 78 | + check_copyright: { |
| 79 | + options: { |
| 80 | + copyrights: [/(2016-2017 Company Limited,).*(XXXX, YYYY\. All Rights Reserved\.)/, /(2015-2016 Company Limited, XXXX, YYYY\. All Rights Reserved\.).*(The Company proprietary software program \(\"Program\"\), is protected by copyrights laws, international treaties and other pending or existing intellectual property rights in YYYY, ZZZZ and other countries\.).*(The Program may contain\/reference third party or open source components, the rights to which continue to ).*(remain with the applicable third party licensors or the open source community as the case may be and nothing ).*(here transfers the rights to the third party and open source components, except as expressly permitted\. ).*(Any unauthorized reproduction, storage, transmission in any form or by any means \(including without limitation to electronic, mechanical, printing, photocopying, recording or otherwise\), or any distribution of this Program,or any portion of it, may result in severe civil and criminal penalties, and will be prosecuted to the maximum extent possible under the law\.)/], |
| 81 | + lines: 6 |
| 82 | + }, |
| 83 | + files: { |
| 84 | + 'custom_options': ['test/fixtures/*.html'] |
| 85 | + } |
| 86 | + }, |
| 87 | +}); |
| 88 | +``` |
| 89 | + |
| 90 | +## Contributing |
| 91 | +In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). |
| 92 | + |
| 93 | +## Release History |
| 94 | +_(Nothing yet)_ |
0 commit comments