write-file

Learn how to write content to a file.

This action writes content to a file, creating it if it does not exist or replacing it if it does. The content can include template expressions to generate dynamic values at runtime.

Example

The following template creates a configuration file with a project name provided as an option:

template.json5
{  "$schema": "https://schema.croct.com/json/v1/template.json",  "title": "Config creator",  "description": "Creates a configuration file.",  "options": {    "name": {      "type": "string",      "description": "The project name.",      "default": "my-app"    }  },  "actions": [    {      "name": "write-file",      "path": "config.json",      "content": "{\n  \"name\": \"${options.name}\"\n}\n"    }  ]}

To apply this template, run:

npx croct@latest use template.json5 --name my-app

Properties

These are the supported properties:

name
string

The action identifier. Always write-file for this action.

path
string

The path to the file to write.

content
string

The content to write to the file.

overwrite(optional)
boolean

Whether to overwrite the file if it already exists.

When not set, a confirmation prompt appears asking the user whether to replace the existing file.