Skip to content

Instantly share code, notes, and snippets.

@pdehaan
Created November 6, 2013 20:44
Show Gist options
  • Save pdehaan/7343753 to your computer and use it in GitHub Desktop.
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.
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