[484] | 1 | # grunt-banner [](https://travis-ci.org/mattstyles/grunt-banner) |
---|
| 2 | |
---|
| 3 | > Adds a simple banner to files |
---|
| 4 | |
---|
| 5 | ## Getting Started |
---|
| 6 | This plugin requires Grunt `~0.4.1` |
---|
| 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-banner --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-banner'); |
---|
| 18 | ``` |
---|
| 19 | |
---|
| 20 | Or if you are using [matchdep](https://github.com/tkellen/node-matchdep) it will be included along with other |
---|
| 21 | `grunt-*` tasks by using this line of JS: |
---|
| 22 | |
---|
| 23 | ```js |
---|
| 24 | require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); |
---|
| 25 | ``` |
---|
| 26 | |
---|
| 27 | ## The "usebanner" task |
---|
| 28 | |
---|
| 29 | _grunt-banner renamed itâs task from `banner` to `usebanner` as a `banner` is often used to hold a banner template |
---|
| 30 | for a number of grunt plugins_ |
---|
| 31 | |
---|
| 32 | ### Overview |
---|
| 33 | In your project's Gruntfile, add a section named `usebanner` to the data object passed into `grunt.initConfig()`. |
---|
| 34 | |
---|
| 35 | The wildcard selector `*` is perfectly valid for selecting targets to add a banner to. |
---|
| 36 | |
---|
| 37 | ```js |
---|
| 38 | grunt.initConfig({ |
---|
| 39 | usebanner: { |
---|
| 40 | taskName: { |
---|
| 41 | options: { |
---|
| 42 | position: 'top' || 'bottom' |
---|
| 43 | banner: '// banner text <%= templates encouraged %>' |
---|
| 44 | }, |
---|
| 45 | files: { |
---|
| 46 | src: [ 'path/to/file.ext', 'path/to/another/*.ext' ] |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | } |
---|
| 50 | }) |
---|
| 51 | ``` |
---|
| 52 | |
---|
| 53 | ### Options |
---|
| 54 | |
---|
| 55 | #### options.position |
---|
| 56 | Type: `String` |
---|
| 57 | Default value: `'top` |
---|
| 58 | Value range: `'top'` or `'bottom'` only |
---|
| 59 | |
---|
| 60 | The position to place the banner - _either_ the top or bottom (other values will default to top) |
---|
| 61 | |
---|
| 62 | #### options.banner |
---|
| 63 | Type: `String` |
---|
| 64 | Default value: `` |
---|
| 65 | |
---|
| 66 | The text to use as a banner. Templated strings are perfectly acceptable and encouraged. |
---|
| 67 | |
---|
| 68 | ### Usage Examples |
---|
| 69 | |
---|
| 70 | In this example an `appConfig` is read from a JSON file and used to populate a `banner` template which |
---|
| 71 | is then used by `grunt-banner` to place at the top of some files. Each file in the array will have the |
---|
| 72 | banner placed on to it and all `.js` files in the `/more-scripts/` folder will have a banner thanks to |
---|
| 73 | the `*` wildcard. |
---|
| 74 | |
---|
| 75 | ```js |
---|
| 76 | var appConfig = grunt.file.readJSON( 'app-config.json' ) || {}; |
---|
| 77 | grunt.initConfig({ |
---|
| 78 | banner: '/* <%= appConfig.info.name %> - version <%= appConfig.info.version %> - ' + |
---|
| 79 | '<%= grunt.template.today("dd-mm-yyyy") %>\n' + |
---|
| 80 | '<%= appConfig.info.description %>\n ' + |
---|
| 81 | '© <%= grunt.template.today("yyyy") %> <%= appConfig.info.author.name %> ' + |
---|
| 82 | '- <%= appConfig.info.author.email %> */\n', |
---|
| 83 | usebanner: { |
---|
| 84 | dist: { |
---|
| 85 | options: { |
---|
| 86 | position: 'top' |
---|
| 87 | banner: '<%= banner %>' |
---|
| 88 | }, |
---|
| 89 | files: { |
---|
| 90 | src: [ 'scripts/main-min.js', 'stylesheets/main-min.css', 'more-scripts/*.js' ] |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | }) |
---|
| 95 | ``` |
---|
| 96 | |
---|
| 97 | ### Notes |
---|
| 98 | |
---|
| 99 | `grunt-banner` simply adds the banner to the head or foot of the files that are specified by |
---|
| 100 | the array passed to `files.src`, it makes no attempt to see if a banner already exists and it |
---|
| 101 | is up to the user to ensure that the file should not already contain a banner. To this end it is |
---|
| 102 | strongly recommended to use the [grunt-contrib-clean](https://github.com/gruntjs/grunt-contrib-clean) |
---|
| 103 | task and only add banners to production-ready code. |
---|
| 104 | |
---|
| 105 | ## Contributing |
---|
| 106 | 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/). |
---|
| 107 | |
---|
| 108 | ## Release History |
---|
| 109 | * 01.05.03 -- v0.1.4 -- Fix for wildcard selector |
---|
| 110 | * 01.05.13 -- v0.1.3 -- Added travis |
---|
| 111 | * 30.04.13 -- v0.1.0 -- Initial release of grunt-banner |
---|