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:
{ "$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:
npx croct@latest use template.json5Filename remapping
Use mapping to rename files during download:
{ "$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:
- namestring
The action identifier. Always download for this action.
- sourcestring
The path relative to the template source to download from.
- destinationstring
The destination path in the project.
- filter(optional)string
A glob pattern to filter which files to download.
- mapping(optional)object
A map of source filenames to destination filenames.
Use this to rename files during download.
- overwrite(optional)boolean
Whether to overwrite existing files at the destination.
- result(optional)object
Variables to capture download information.
- destination(optional)string
The variable name to store the resolved destination path.
- destination(optional)