Skip to content

Instantly share code, notes, and snippets.

@cowboy
Last active December 10, 2015 21:19
Show Gist options
  • Save cowboy/4494697 to your computer and use it in GitHub Desktop.
Save cowboy/4494697 to your computer and use it in GitHub Desktop.
Grunt: a dynamic banner can include src file lists!
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
// This has to be attached as a property of either grunt, global, or set
// in the config like so (the names here are arbitrary).
_util: {path: require('path')},
// Task config.
banner_test: {
options: {
banner: '/* (c) <%= grunt.template.today("yyyy") %>, etc.' +
'<% if (grunt.task.current.filesSrc.length > 1) { %>' +
' Includes: <%= grunt.task.current.filesSrc.map(_util.path.basename).join(", ") %>' +
'<% } %>' +
' */',
},
nofiles: {},
onefile: {
files: [
{src: 'lib/grunt.js', dest: 'build/grunt.min.js'},
]
},
manyfiles: {
files: [
{src: 'lib/grunt.js', dest: 'build/grunt.min.js'},
{src: 'lib/grunt/cli.js', dest: 'build/grunt/cli.min.js'},
{src: 'lib/grunt/config.js', dest: 'build/grunt/config.min.js'},
]
},
},
});
// Sample task.
grunt.registerMultiTask('banner_test', function() {
var options = this.options({});
console.log('Banner:', options.banner);
});
grunt.registerTask('default', ['banner_test']);
};
$ grunt
Running "banner_test:nofiles" (banner_test) task
Banner: /* (c) 2013, etc. */
Running "banner_test:onefile" (banner_test) task
Banner: /* (c) 2013, etc. */
Running "banner_test:manyfiles" (banner_test) task
Banner: /* (c) 2013, etc. Includes: grunt.js, cli.js, config.js */
Done, without errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment