-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a9b7916
Showing
12 changed files
with
410 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.vscode | ||
node_modules | ||
npm-debug.log | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"curly": true, | ||
"eqeqeq": true, | ||
"immed": true, | ||
"latedef": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"sub": true, | ||
"undef": true, | ||
"boss": true, | ||
"eqnull": true, | ||
"node": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* grunt-check-copyright | ||
* | ||
* | ||
* Copyright (c) 2018 vamsee | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = function(grunt) { | ||
|
||
// Project configuration. | ||
grunt.initConfig({ | ||
jshint: { | ||
all: [ | ||
'Gruntfile.js', | ||
'tasks/*.js', | ||
'<%= nodeunit.tests %>' | ||
], | ||
options: { | ||
jshintrc: '.jshintrc', | ||
reporterOutput: "" | ||
} | ||
}, | ||
|
||
// Before generating any new files, remove any previously-created files. | ||
clean: { | ||
tests: ['tmp'] | ||
}, | ||
|
||
// Configuration to be run (and then tested). | ||
check_copyright: { | ||
default_options: { | ||
options: { | ||
}, | ||
files: { | ||
'default_options': ['test/fixtures/*.js'] | ||
} | ||
}, | ||
custom_options: { | ||
options: { | ||
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\.)/], | ||
lines: 6 | ||
}, | ||
files: { | ||
'custom_options': ['test/fixtures/*.html'] | ||
} | ||
} | ||
}, | ||
|
||
// Unit tests. | ||
nodeunit: { | ||
tests: ['test/*_test.js'] | ||
} | ||
|
||
}); | ||
|
||
// Actually load this plugin's task(s). | ||
grunt.loadTasks('tasks'); | ||
|
||
// These plugins provide necessary tasks. | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-contrib-clean'); | ||
grunt.loadNpmTasks('grunt-contrib-nodeunit'); | ||
|
||
// Whenever the "test" task is run, first clean the "tmp" dir, then run this | ||
// plugin's task(s), then test the result. | ||
grunt.registerTask('test', ['clean', 'nodeunit']); | ||
|
||
// By default, lint and run all tests. | ||
grunt.registerTask('default', ['jshint', 'test', 'check_copyright']); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2018 vamsee | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# grunt-check-copyright | ||
|
||
> Grunt plugin to check if copyright is present in files | ||
## Getting Started | ||
This plugin requires Grunt `~0.4.5` | ||
|
||
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: | ||
|
||
```shell | ||
npm install grunt-check-copyright --save-dev | ||
``` | ||
|
||
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: | ||
|
||
```js | ||
grunt.loadNpmTasks('grunt-check-copyright'); | ||
``` | ||
|
||
## The "check_copyright" task | ||
|
||
### Overview | ||
In your project's Gruntfile, add a section named `check_copyright` to the data object passed into `grunt.initConfig()`. | ||
|
||
```js | ||
grunt.initConfig({ | ||
check_copyright: { | ||
options: { | ||
// Task-specific options go here. | ||
}, | ||
your_target: { | ||
// Target-specific file lists and/or options go here. | ||
}, | ||
}, | ||
}); | ||
``` | ||
|
||
### Options | ||
|
||
#### options.copyrights | ||
Type: `Array` | ||
Default value: `[/(Copyright .*\. All Rights Reserved\.)/]` | ||
|
||
An array containing the various copyrights to check in the list of files specified. | ||
|
||
#### options.lines | ||
Type: `Number` | ||
Default value: `5` | ||
|
||
A number value that is used to check a file first 'n' lines for the copyright. | ||
|
||
### Usage Examples | ||
|
||
#### Default Options | ||
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. | ||
|
||
Note: Here we use the default options for lines and copyright as specified [here](#options). | ||
|
||
```js | ||
grunt.initConfig({ | ||
check_copyright: { | ||
options: { | ||
}, | ||
files: { | ||
'default_options': ['test/fixtures/*.js'] | ||
} | ||
}, | ||
}); | ||
``` | ||
|
||
#### Custom Options | ||
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. | ||
|
||
Also, you can see that the `copyrights` array is trying to match two different format of copyright. | ||
|
||
```js | ||
grunt.initConfig({ | ||
check_copyright: { | ||
options: { | ||
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\.)/], | ||
lines: 6 | ||
}, | ||
files: { | ||
'custom_options': ['test/fixtures/*.html'] | ||
} | ||
}, | ||
}); | ||
``` | ||
|
||
## Contributing | ||
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/). | ||
|
||
## Release History | ||
_(Nothing yet)_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "grunt-check-copyright", | ||
"description": "Grunt plugin to check if copyright is present in files", | ||
"version": "0.1.0", | ||
"homepage": "", | ||
"author": { | ||
"name": "vamsee", | ||
"email": "vamsee147@gmail.com" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Vamsee147/grunt-check-copyright.git" | ||
}, | ||
"bugs": { | ||
"url": "" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "/blob/master/LICENSE-MIT" | ||
} | ||
], | ||
"engines": { | ||
"node": ">= 0.8.0" | ||
}, | ||
"scripts": { | ||
"test": "grunt test" | ||
}, | ||
"devDependencies": { | ||
"grunt-contrib-jshint": "^0.9.2", | ||
"grunt-contrib-clean": "^0.5.0", | ||
"grunt-contrib-nodeunit": "^0.3.3", | ||
"grunt": "~0.4.5" | ||
}, | ||
"keywords": [ | ||
"gruntplugin", | ||
"copyright", | ||
"check-copyright", | ||
"check_copyright" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* grunt-check-copyright | ||
* | ||
* | ||
* Copyright (c) 2018 vamsee | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = function(grunt) { | ||
|
||
// Please see the Grunt documentation for more information regarding task | ||
// creation: http://gruntjs.com/creating-tasks | ||
|
||
grunt.registerMultiTask('check_copyright', 'Grunt plugin to check if copyright is present in files', function() { | ||
var done = this.async(); | ||
var options = this.options({ | ||
force: grunt.option('force') === true, | ||
copyrights: [/(Copyright .*\. All Rights Reserved\.)/], | ||
lines: 5 | ||
}); | ||
var files = this.files; | ||
|
||
var noCopyrightFiles = []; | ||
|
||
// Merge task-specific and/or target-specific options with these defaults. | ||
options['copyrights'] = grunt.option('copyrights') || options['copyrights']; | ||
options['lines'] = grunt.option('lines') || options['lines']; | ||
|
||
// check if there are files to test | ||
if (this.filesSrc.length === 0) { | ||
grunt.log.write('No files to check...'); | ||
grunt.log.ok(); | ||
return true; | ||
} | ||
|
||
// Iterate over all specified file groups. | ||
this.files.forEach(function(f) { | ||
|
||
// Concat specified files. | ||
var src = f.src.filter(function(filepath) { | ||
// Warn on and remove invalid source files (if nonull was set). | ||
if (grunt.file.exists(filepath) && grunt.file.isFile(filepath)) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}).map(function(filepath) { | ||
// Read file source. | ||
var file = grunt.file.read(filepath).split("\r\n"); | ||
var lines = file.slice(0, options.lines).join(); | ||
var hasCopyright = false; | ||
options.copyrights.forEach(function (copyright) { | ||
if (copyright.test(lines)) { | ||
hasCopyright = true; | ||
} | ||
}); | ||
if (!hasCopyright) { | ||
return filepath; | ||
} else { | ||
return; | ||
} | ||
}).filter(function(ele) { | ||
if (ele) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}); | ||
|
||
// Print a success message. | ||
if (src.length > 0) { | ||
grunt.log.error(src.join(grunt.util.normalizelf('\n'))); | ||
done(new Error()); | ||
} else { | ||
grunt.log.ok('All files have copyright'); | ||
done(); | ||
} | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* | ||
* Copyright (c) 2018 vamsee. All Rights Reserved. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
var path = require('path'); | ||
var exec = require('child_process').exec; | ||
var execOptions = { | ||
cwd: path.join(__dirname, '..') | ||
}; | ||
|
||
exports.tests = { | ||
default_options: function(test) { | ||
test.expect(2); | ||
exec('grunt check_copyright:default_options', execOptions, function(error, stdout) { | ||
test.equal( | ||
stdout.indexOf("test/fixtures/fail.js") !== -1, | ||
true, | ||
'Copyright fail file found in output.' | ||
); | ||
test.equal( | ||
stdout.indexOf("test/fixtures/pass.js") === -1, | ||
true, | ||
'Copyright pass file not found in output.' | ||
); | ||
test.done(); | ||
}); | ||
}, | ||
|
||
custom_options: function(test) { | ||
test.expect(2); | ||
exec('grunt check_copyright:custom_options', execOptions, function(error, stdout) { | ||
test.equal( | ||
stdout.indexOf("test/fixtures/fail.html") !== -1, | ||
true, | ||
'Copyright fail file found in output.' | ||
); | ||
test.equal( | ||
stdout.indexOf("test/fixtures/pass.html") === -1, | ||
true, | ||
'Copyright pass file not found in output.' | ||
); | ||
test.done(); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<title>Copyright Check - Fail</title> | ||
</head> | ||
<body> | ||
<h1>Testing for copyright</h1> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("sample file to fail copyright check"); |
Oops, something went wrong.