/grunt-see-url

Download files from the internet via grunt.

Primary LanguageJavaScriptMIT LicenseMIT

grunt-curl

Download files from the internet via grunt.

Getting Started

Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-curl

Then add this line to your project's grunt.js gruntfile:

grunt.loadNpmTasks('grunt-curl');

Documentation

grunt-curl retrieves data via request's GET method and writes it to file.

We register two grunt tasks

grunt.initConfig({
  // Grab single files
  curl: {
    // Short format (dest: src)
    'location/to/download/file.js': 'http://files.com/path/to/file.js',

    // Long format
    long: {
      src: 'http://files.com/path/to/file.js',
      dest: 'location/to/download/file.js'
    }
  },
  // Grab multiple files
  'curl-dir': {
    // Short format (dest folder: [src1, src2])
    // These will be saved as 'location/to/save/files/file1.js'
    //    and 'location/to/save/files/file2.js'
    'location/to/save/files': [
      'http://files.com/path/to/file1.js',
      'http://generic.com/scripts/file2.js'
    ],

    // Long format
    long: {
      src: [
        'http://files.com/path/to/file1.js',
        'http://files.com/path/to/file2.js'
      ],
      dest: 'location/to/save/files'
    },

    // src files will expand to same file1.js and file2.js as long format
    braceExpansion: {
      src: ['http://files.com/path/to/{file1,file2}.js'],
      dest: 'location/to/save/files'
    },

    // Custom filepaths
    // This will save file1.js to location/to/save/files/path/to/file1.js
    //    and file2.js to location/to/save/files/scripts/file2.js
    customFilepaths: {
      src: [
        'http://files.com/path/to/file1.js',
        'http://generic.com/scripts/file2.js'
      ],
      router: function (url) {
        return url.replace('http://files.com/', '').replace('http://generic.com/', '');
      },
      dest: 'location/to/save/files'
    }
  }
}):

and a grunt helper

grunt.helper('curl', url, function handleData (err, content) {
  // Handle error and use content
});

Contributing

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 and test via npm test.

License

Copyright (c) 2013 Todd Wolfson Licensed under the MIT license.