Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

grunt-curl

twolfson5.8kdeprecated2.5.1

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

Download files from the internet via grunt.

gruntplugin, grunt, curl, download, request, file, url, uri

readme

grunt-curl Build status

Download files from the internet via grunt.

This was created for dependency management via grunt-curl and grunt-zip as a low-tech alternative to bower and similar solutions.

http://twolfson.com/2014-01-19-low-tech-dependency-management-via-grunt-tasks

Getting Started

grunt-curl can be installed via npm: npm install grunt-curl

Then, add and configure it in your grunt file:

module.exports = function (grunt) {
  // Configure `curl` with URLs
  // If you would like to download multiple files
  // to the same directory, there is `curl-dir`
  grunt.initConfig({
    curl: {
      'location/to/download/github.html': 'http://github.com/',
    }
  });

  // Load in `grunt-curl`
  grunt.loadNpmTasks('grunt-curl');
};

Now, we can run our task:

$ grunt curl
Running "curl:location/to/download/github.html" (curl) task
File "location/to/download/github.html" created.

Done, without errors.

Documentation

grunt-curl creates 2 grunt tasks for you to use/configure, curl and curl-dir. curl is designed for downloading single files at a time. curl-dir is designed for downloading multiple files to a common directory.

Both tasks support accepting request] parameters as a src file. [Here is an example creating a POST request.

curl

We support 2 different formats for configuring curl.

Short format

The short format relies on grunt's support of {dest: src}

curl: {
  'location/to/download/file.js': 'http://files.com/path/to/file.js'
}

This format is suggested only if you don't need to run curl tasks separately

grunt curl

If you want to run this task standalone, it must be executed via:

grunt curl:dest
# grunt curl:location/to/download/file.js

Long format

curl: {
  'task-name': {
    src: 'http://files.com/path/to/file.js',
    dest: 'location/to/download/file.js'
  }
}

This can be run standalone via

grunt curl:task-name

Using request options

This is an example of the long format leveraging request parameters for making a POST request.

curl: {
  'task-name': {
    src: {
      url: 'http://files.com/path/to/file.js',
      method: 'POST',
      body: 'abc'
    },
    dest: 'location/to/download/file.js'
  }
}

curl-dir

curl-dir supports 2 configuration formats.

Short format

As with curl, we leverage grunt's {dest: src} format for our short format.

'curl-dir': {
  // 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'
  ]
}

As with before, this can be executed via grunt curl-dir but will execute other tasks at the same level. To run this task standalone, it must be run via:

grunt curl-dir:location/to/save/files

Long format

'curl-dir': {
  'task-name': {
    src: [
      'http://files.com/path/to/file1.js',
      'http://files.com/path/to/file2.js'
    ],
    dest: 'location/to/save/files'
  }
}

This task can be executed from the command line via

grunt curl-dir:task-name

Brace expansion

curl-dir supports brace expansion for src in both formats.

'curl-dir': {
  'brace-expansion': {
    src: ['http://files.com/path/to/{file1,file2}.js'],
    // Expands to: [
    //  'http://files.com/path/to/file1.js',
    //  'http://files.com/path/to/file2.js'
    // ]
    dest: 'location/to/save/files'
  }
}

Filepath mapping

URLs can be mapped to custom filepaths via the router option in the long format.

'curl-dir': {
  'custom-filepaths': {
    src: [
      'http://files.com/path/to/file1.js',
      'http://generic.com/scripts/file2.js'
    ],
    router: function (url) {
      // Save `file1.js` to 'location/to/save/files/hello/world/file1.js'
      // and `file2.js` to 'location/to/save/files/goodbye/moon/file2.js'
      var filepath = url.replace('http://files.com/path/to', 'hello/world');
      return url.replace('http://generic.com/scripts', 'goodbye/moon');
    },
    dest: 'location/to/save/files'
  }
}

Using request options

As demonstrated in curl, we can use request options to leverage special HTTP actions (e.g. make a POST request).

'curl-dir': {
  custom: {
    src: [{
      url: 'http://files.com/path/to/file.js',
      method: 'POST',
      body: 'abc'
    }],
    dest: 'location/to/save/files'
  }
}

Examples

Using a proxy

Using request options we can add a proxy to our requests

curl: {
  custom: {
    src: {
      url: 'http://google.com/',
      proxy: 'http://127.0.0.1:9001/'
    },
    dest: 'google.html'
  }
}

Using authentication

Using request options we can add authentication to our requests

curl: {
  custom: {
    src: {
      url: 'http://secureserver.com/members',
      auth: {
        user: 'my-username',
        pass: 'my-password'
      }
    },
    dest: 'secure.html'
  }
}

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.

Donating

Support this project and others by twolfson via donations.

http://twolfson.com/support-me

Unlicense

As of Jun 14 2014, Todd Wolfson has released this repository and its contents to the public domain.

It has been released under the UNLICENSE.

Prior to Jun 14 2014, this repository and its contents were licensed under the MIT license.

changelog

grunt-curl changelog

2.5.1 - Upgraded to shell-quote@1.6.1 to fix GitHub vulnerability warning

2.5.0 - Upgraded to lodash@4 to fix GitHub vulnerability warning

2.4.2 - Upgraded to `express@3.21.2` to fix GitHub vulnerability warning

2.4.1 - Replaced Gittip with support me page

2.4.0 - Upgraded to `request@2.83.0` to fix security flaw via @maxcutler in #40

2.3.1 - Fixed Travis CI configuration

2.3.0 - Added foundry for releases

2.2.1 - Added authentication example via @lynchmaniac in #39

2.2.0 - Upgraded to `request@2.54.0` to fix security flaw via @duereg in #31

2.1.1 - Fixed Travis CI configuration

2.1.0 - Added support for decoding gzipped content via gzip: true request option

2.0.3 - Added example for using a proxy

2.0.2 - Updated README

2.0.1 - Fixed regression with exiting early and bad event listener

2.0.0 - Moved to streams for creating files, deprecated helper. Fixes #21

1.5.1 - Added test for local GET in order to resolve #18 faster

1.5.0 - Moved from doubleshot to mocha to make tests more canonical for contributors

1.4.0 - Moved from grunt.util dependencies to async and lodash dependencies via @shinnn #13

1.3.1 - Added Travis CI

1.3.0 - Upgraded to latest grunt-retro to support description-less multitasks

1.2.1 - Removing accidental console.log

1.2.0 - Added support for all request options

Before 1.2.0 - See git log