# download

Learn how to download files from the template source.

This action downloads files into the project directory. The source can be a URL or a path relative to the template location.

## Example

The following template downloads a component file into the project:

**template.json5**

```json5
{
  "$schema": "https://schema.croct.com/json/v1/template.json",
  "title": "Component downloader",
  "description": "Downloads a component file.",
  "actions": [
    {
      "name": "download",
      "source": "./code/hero.tsx",
      "destination": "src/components",
      "overwrite": true
    }
  ]
}
```

To apply this template, run:

```sh
croct use template.json5
```

### Filename remapping

Use [`mapping`](#mapping-prop) to rename files during download:

**template.json5**

```json5
{
  "$schema": "https://schema.croct.com/json/v1/template.json",
  "title": "Dynamic extension",
  "description": "Downloads a component with a dynamic file extension.",
  "options": {
    "typescript": {
      "type": "boolean",
      "description": "Whether to use TypeScript.",
      "default": true
    }
  },
  "actions": [
    {
      "name": "download",
      "source": "./code/components",
      "destination": "src/components",
      "filter": "hero.*",
      "mapping": {
        "hero.tsx": "hero${options.typescript ? '.tsx' : '.jsx'}"
      }
    }
  ]
}
```

## Properties

These are the supported properties:

- `name`: `string`

  The action identifier. Always `download` for this action.

- `source`: `string`

  The path relative to the template source to download from.

- `destination`: `string`

  The destination path in the project.

- `filter`: `string` (optional)

  A glob pattern to filter which files to download.

- `mapping`: `object` (optional)

  A map of source filenames to destination filenames.

  Use this to rename files during download.

- `overwrite`: `boolean` (optional)

  Whether to overwrite existing files at the destination.

- `result`: `object` (optional)

  Variables to capture download information.

  - `destination`: `string` (optional)

    The variable name to store the resolved destination path.

## Explore

- [Write file](/reference/cli/templates/actions/write-file): Learn how to write content to a file.
- [Create directory](/reference/cli/templates/actions/create-directory): Learn how to create a directory for downloads.
- [Move path](/reference/cli/templates/actions/move-path): Learn how to move the downloaded file.
- [Delete path](/reference/cli/templates/actions/delete-path): Learn how to remove a downloaded file.
