[484] | 1 | # grunt-curl [](https://www.gittip.com/twolfson/) |
---|
| 2 | |
---|
| 3 | Download files from the internet via grunt. |
---|
| 4 | |
---|
| 5 | ## Getting Started |
---|
| 6 | Install this grunt plugin next to your project's [grunt.js gruntfile][getting_started] with: `npm install grunt-curl` |
---|
| 7 | |
---|
| 8 | Then add this line to your project's `grunt.js` gruntfile: |
---|
| 9 | |
---|
| 10 | ```javascript |
---|
| 11 | grunt.loadNpmTasks('grunt-curl'); |
---|
| 12 | ``` |
---|
| 13 | |
---|
| 14 | [grunt]: http://gruntjs.com/ |
---|
| 15 | [getting_started]: https://github.com/gruntjs/grunt/blob/master/docs/getting_started.md |
---|
| 16 | |
---|
| 17 | ## Documentation |
---|
| 18 | `grunt-curl` retrieves data via [request][request]'s GET method and writes it to file. |
---|
| 19 | |
---|
| 20 | We register two grunt tasks |
---|
| 21 | ```js |
---|
| 22 | grunt.initConfig({ |
---|
| 23 | // Grab single files |
---|
| 24 | curl: { |
---|
| 25 | // Short format (dest: src) |
---|
| 26 | 'location/to/download/file.js': 'http://files.com/path/to/file.js', |
---|
| 27 | |
---|
| 28 | // Long format |
---|
| 29 | long: { |
---|
| 30 | src: 'http://files.com/path/to/file.js', |
---|
| 31 | dest: 'location/to/download/file.js' |
---|
| 32 | } |
---|
| 33 | }, |
---|
| 34 | // Grab multiple files |
---|
| 35 | 'curl-dir': { |
---|
| 36 | // Short format (dest folder: [src1, src2]) |
---|
| 37 | // These will be saved as 'location/to/save/files/file1.js' |
---|
| 38 | // and 'location/to/save/files/file2.js' |
---|
| 39 | 'location/to/save/files': [ |
---|
| 40 | 'http://files.com/path/to/file1.js', |
---|
| 41 | 'http://generic.com/scripts/file2.js' |
---|
| 42 | ], |
---|
| 43 | |
---|
| 44 | // Long format |
---|
| 45 | long: { |
---|
| 46 | src: [ |
---|
| 47 | 'http://files.com/path/to/file1.js', |
---|
| 48 | 'http://files.com/path/to/file2.js' |
---|
| 49 | ], |
---|
| 50 | dest: 'location/to/save/files' |
---|
| 51 | }, |
---|
| 52 | |
---|
| 53 | // src files will expand to same file1.js and file2.js as long format |
---|
| 54 | braceExpansion: { |
---|
| 55 | src: ['http://files.com/path/to/{file1,file2}.js'], |
---|
| 56 | dest: 'location/to/save/files' |
---|
| 57 | }, |
---|
| 58 | |
---|
| 59 | // Custom filepaths |
---|
| 60 | // This will save file1.js to location/to/save/files/path/to/file1.js |
---|
| 61 | // and file2.js to location/to/save/files/scripts/file2.js |
---|
| 62 | customFilepaths: { |
---|
| 63 | src: [ |
---|
| 64 | 'http://files.com/path/to/file1.js', |
---|
| 65 | 'http://generic.com/scripts/file2.js' |
---|
| 66 | ], |
---|
| 67 | router: function (url) { |
---|
| 68 | return url.replace('http://files.com/', '').replace('http://generic.com/', ''); |
---|
| 69 | }, |
---|
| 70 | dest: 'location/to/save/files' |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | }): |
---|
| 74 | ``` |
---|
| 75 | |
---|
| 76 | and a grunt helper |
---|
| 77 | ```js |
---|
| 78 | grunt.helper('curl', url, function handleData (err, content) { |
---|
| 79 | // Handle error and use content |
---|
| 80 | }); |
---|
| 81 | ``` |
---|
| 82 | |
---|
| 83 | [request]: https://github.com/mikeal/request |
---|
| 84 | |
---|
| 85 | ## Contributing |
---|
| 86 | In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint your code using [grunt][grunt] and test via `npm test`. |
---|
| 87 | |
---|
| 88 | ## License |
---|
| 89 | Copyright (c) 2013 Todd Wolfson |
---|
| 90 | Licensed under the MIT license. |
---|