Created
November 6, 2013 20:44
-
-
Save pdehaan/7343753 to your computer and use it in GitHub Desktop.
Quickly check for the existence of a specific copyright header in a project using a custom Grunt task.
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
module.exports = function (grunt) { | |
grunt.initConfig({ | |
copyright: { | |
files: [ | |
"**/*.js", | |
"!**/node_modules/**" | |
], | |
options: { | |
pattern: "This Source Code Form is subject to the terms of the Mozilla Public" | |
} | |
} | |
}); | |
grunt.registerMultiTask('copyright', 'Copyright all the things!', function () { | |
var pattern = this.options().pattern; | |
var files = this.filesSrc.map(function (file) { | |
return { | |
"name": file, | |
"txt": grunt.file.read(file, "utf8") | |
}; | |
}).filter(function (file) { | |
return !file.txt.match(pattern); | |
}); | |
if (files.length) { | |
grunt.log.subhead("The following files are missing copyright headers:"); | |
files.forEach(function (file) { | |
grunt.log.warn(file.name); | |
}); | |
return false; | |
} | |
}); | |
grunt.registerTask('default', ['copyright']); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment