# grunt-curl

> Download files from the internet via grunt.

Latest version **2.5.1** (published 2019-03-07) · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install grunt-curl
pnpm add grunt-curl
yarn add grunt-curl
bun add grunt-curl
```

Provides the command `grunt-curl`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.5.1 |
| Published | 2019-03-07 |
| First published | 2013-01-10 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 4.0.0 |
| Dependencies | 4 |
| Unpacked size | 148.6 KB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 71 |
| Author | Todd Wolfson |
| Maintainers | twolfson |
| Keywords | gruntplugin, grunt, curl, download, request, file, url, uri |

## Links

- npm: https://www.npmjs.com/package/grunt-curl
- Repository: https://github.com/twolfson/grunt-curl
- Issues: https://github.com/twolfson/grunt-curl/issues
- npm.io page: https://npm.io/package/grunt-curl

## Dependencies (4)

- [async](https://npm.io/package/async.md) ~0.2.10
- [lodash](https://npm.io/package/lodash.md) ~4.17.11
- [request](https://npm.io/package/request.md) ~2.83.0
- [grunt-retro](https://npm.io/package/grunt-retro.md) ~0.7.0

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 2.5.1 (latest) — 2019-03-07
- 2.5.0 — 2018-10-31
- 2.4.2 — 2018-10-31
- 2.4.1 — 2017-11-14
- 2.4.0 — 2017-11-02
- 2.3.1 — 2017-11-02
- 2.3.0 — 2017-11-02
- 2.2.1 — 2017-05-10
- 2.2.0 — 2015-04-02
- 2.1.1 — 2015-04-02
- 2.1.0 — 2015-01-10
- 2.0.3 — 2014-09-06
- 2.0.2 — 2014-06-14
- 2.0.1 — 2014-06-14
- 2.0.0 — 2014-06-14
- … 18 more at https://npm.io/package/grunt-curl/versions

## README

# grunt-curl [![Build status](https://travis-ci.org/twolfson/grunt-curl.png?branch=master)](https://travis-ci.org/twolfson/grunt-curl)

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

[grunt]: http://gruntjs.com/
[`grunt-curl`]: https://github.com/twolfson/grunt-curl
[`grunt-zip`]: https://github.com/twolfson/grunt-zip

## Getting Started
`grunt-curl` can be installed via npm: `npm install grunt-curl`

Then, add and configure it in your grunt file:

```js
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:

```bash
$ 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][post-example].

[`request`]: https://github.com/mikeal/request
[post-example]: #using-request-options

### `curl`
We support 2 different formats for configuring `curl`.

#### Short format
The short format relies on [`grunt's` support of `{dest: src}`][grunt-short-format]

[grunt-short-format]: http://gruntjs.com/configuring-tasks#older-formats

```js
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

```bash
grunt curl
```

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

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

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

This can be run standalone via

```bash
grunt curl:task-name
```

#### Using request options
This is an example of the long format leveraging [`request`][] parameters for making a `POST` request.

```js
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.

```js
'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:

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

#### Long format
```js
'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

```bash
grunt curl-dir:task-name
```

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

```js
'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.

```js
'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).

```js
'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

```js
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

```js
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][grunt] and test via `npm test`.

## Donating
Support this project and [others by twolfson][twolfson-projects] via [donations][twolfson-support-me].

<http://twolfson.com/support-me>

[twolfson-projects]: http://twolfson.com/projects
[twolfson-support-me]: 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][].

[UNLICENSE]: UNLICENSE

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

[MIT license]: https://github.com/twolfson/grunt-curl/blob/1.5.1/LICENSE-MIT

---
_Source: https://npm.io/package/grunt-curl · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
